Skip to content

Commit

Permalink
fix: enhance user errors to point to snyk docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 authored and Rob Cresswell committed Jul 27, 2018
1 parent a54c615 commit f0a43a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
9 changes: 8 additions & 1 deletion lib/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
var fs = require('then-fs');
var path = require('path');
var debug = require('debug')('snyk');
var chalk = require('chalk');

var DETECTABLE_FILES = [
'yarn.lock',
Expand Down Expand Up @@ -76,7 +77,13 @@ function detectPackageManager(root, options) {
packageManager = detectPackageManagerFromRegistry(registry);
}
if (!packageManager) {
throw new Error('Could not autodetect package manager for ' + root);
throw new Error('Could not detect supported target files in ' + root +
'.\nPlease see our documentation for supported languages and ' +
'target files: ' +
chalk.underline(
'https://support.snyk.io/getting-started/languages-support'
) +
' and make sure you are in the right directory.');
}
return packageManager;
}
Expand Down
16 changes: 12 additions & 4 deletions lib/protect/ensure-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ module.exports = ensurePatchExists;

var hasbin = require('hasbin');
var analytics = require('../analytics');
var chalk = require('chalk');

function ensurePatchExists() {
return new Promise(function (resolve, reject) {
return hasbin('patch', function (exists) {
if (!exists) {
var err = new Error('Snyk couldn\'t patch the specified ' +
'vulnerabilities because GNU\'s patch is not ' +
'available. Please install \'patch\' ' +
'and try again.');
var err =
new Error(
'Snyk couldn\'t patch the specified ' +
'vulnerabilities because GNU\'s patch is not ' +
'available. Please install \'patch\' ' +
'and try again. \n For more information ' +
'please see our support page: '
+ chalk.underline(
'https://support.snyk.io' +
'/snyk-cli/snyk-protect-requires-the-patch-binary.'
));
analytics.add('patch-binary-missing', {
message: err.message,
});
Expand Down
3 changes: 2 additions & 1 deletion lib/snyk-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = test;

var detect = require('../detect');
var runTest = require('./run-test');
var chalk = require('chalk');

function test(root, options, callback) {
if (typeof options === 'function') {
Expand Down Expand Up @@ -33,7 +34,7 @@ function executeTest(root, options) {
return res;
});
} catch (error) {
return Promise.reject(error);
return Promise.reject(chalk.red.bold(error));
}
}

Expand Down

0 comments on commit f0a43a5

Please sign in to comment.