From d0b05955fd842f26a9553c31453a80ffa2a57a30 Mon Sep 17 00:00:00 2001 From: Lucian Rosu Date: Wed, 31 Aug 2022 17:57:41 +0300 Subject: [PATCH] fix: go binary explicit error --- lib/index.ts | 6 ++++++ package.json | 1 + 2 files changed, 7 insertions(+) diff --git a/lib/index.ts b/lib/index.ts index ed4f215..79d93bc 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,6 +1,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as tmp from 'tmp'; +import { lookpath } from 'lookpath'; import debugLib = require('debug'); import * as graphlib from '@snyk/graphlib'; import { DepGraphBuilder, DepGraph } from '@snyk/dep-graph'; @@ -43,6 +44,11 @@ interface Options { export async function inspect(root, targetFile, options: Options = {}) { options.debug ? debugLib.enable('snyk-go-plugin') : debugLib.disable(); + const goPath = await lookpath('go'); + if (!goPath) { + throw new Error('The "go" command is not available on your system. To scan your dependencies in the CLI, you must ensure you have first installed the relevant package manager.'); + } + const result = await Promise.all([ getMetaData(root, targetFile), getDependencies(root, targetFile, options.args), diff --git a/package.json b/package.json index 6a7a276..c43c679 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@snyk/dep-graph": "^1.23.1", "@snyk/graphlib": "2.1.9-patch.3", "debug": "^4.1.1", + "lookpath": "^1.2.2", "snyk-go-parser": "1.4.1", "tmp": "0.2.1", "tslib": "^1.10.0"