snyk 1.776.0 → 1.777.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/exit-codes.d.ts +5 -0
- package/dist/cli/index.js +119 -15
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/main.d.ts +1 -0
- package/dist/lib/unexpected-error.d.ts +8 -0
- package/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -27187,6 +27187,22 @@ function copy(str) {
|
|
|
27187
27187
|
exports.copy = copy;
|
|
27188
27188
|
|
|
27189
27189
|
|
|
27190
|
+
/***/ }),
|
|
27191
|
+
|
|
27192
|
+
/***/ 80079:
|
|
27193
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
27194
|
+
|
|
27195
|
+
"use strict";
|
|
27196
|
+
|
|
27197
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
27198
|
+
exports.EXIT_CODES = void 0;
|
|
27199
|
+
exports.EXIT_CODES = {
|
|
27200
|
+
VULNS_FOUND: 1,
|
|
27201
|
+
ERROR: 2,
|
|
27202
|
+
NO_SUPPORTED_PROJECTS_DETECTED: 3,
|
|
27203
|
+
};
|
|
27204
|
+
|
|
27205
|
+
|
|
27190
27206
|
/***/ }),
|
|
27191
27207
|
|
|
27192
27208
|
/***/ 33402:
|
|
@@ -27195,6 +27211,28 @@ exports.copy = copy;
|
|
|
27195
27211
|
"use strict";
|
|
27196
27212
|
|
|
27197
27213
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
27214
|
+
const unexpected_error_1 = __webpack_require__(89088);
|
|
27215
|
+
const exit_codes_1 = __webpack_require__(80079);
|
|
27216
|
+
/**
|
|
27217
|
+
* By using a dynamic import, we can add error handlers before evaluating any
|
|
27218
|
+
* further modules. This way, if a module has errors, it'll be caught and
|
|
27219
|
+
* handled as we expect.
|
|
27220
|
+
*/
|
|
27221
|
+
unexpected_error_1.callHandlingUnexpectedErrors(async () => {
|
|
27222
|
+
const { main } = await Promise.resolve().then(() => __webpack_require__(64514));
|
|
27223
|
+
await main();
|
|
27224
|
+
}, exit_codes_1.EXIT_CODES.ERROR);
|
|
27225
|
+
|
|
27226
|
+
|
|
27227
|
+
/***/ }),
|
|
27228
|
+
|
|
27229
|
+
/***/ 64514:
|
|
27230
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
27231
|
+
|
|
27232
|
+
"use strict";
|
|
27233
|
+
|
|
27234
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
27235
|
+
exports.main = void 0;
|
|
27198
27236
|
const Debug = __webpack_require__(15158);
|
|
27199
27237
|
const pathLib = __webpack_require__(85622);
|
|
27200
27238
|
// import args as a first internal module
|
|
@@ -27225,12 +27263,8 @@ const json_file_output_1 = __webpack_require__(83421);
|
|
|
27225
27263
|
const empty_sarif_output_error_1 = __webpack_require__(53731);
|
|
27226
27264
|
const invalid_detection_depth_value_1 = __webpack_require__(80401);
|
|
27227
27265
|
const utils_1 = __webpack_require__(61721);
|
|
27266
|
+
const exit_codes_1 = __webpack_require__(80079);
|
|
27228
27267
|
const debug = Debug('snyk');
|
|
27229
|
-
const EXIT_CODES = {
|
|
27230
|
-
VULNS_FOUND: 1,
|
|
27231
|
-
ERROR: 2,
|
|
27232
|
-
NO_SUPPORTED_PROJECTS_DETECTED: 3,
|
|
27233
|
-
};
|
|
27234
27268
|
async function runCommand(args) {
|
|
27235
27269
|
const commandResult = await args.method(...args.options._);
|
|
27236
27270
|
const res = analytics.addDataAndSend({
|
|
@@ -27264,19 +27298,19 @@ async function handleError(args, error) {
|
|
|
27264
27298
|
var _a;
|
|
27265
27299
|
spinner_1.spinner.clearAll();
|
|
27266
27300
|
let command = 'bad-command';
|
|
27267
|
-
let exitCode = EXIT_CODES.ERROR;
|
|
27301
|
+
let exitCode = exit_codes_1.EXIT_CODES.ERROR;
|
|
27268
27302
|
const noSupportedManifestsFound = (_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Could not detect supported target files in');
|
|
27269
27303
|
const noSupportedSastFiles = error instanceof errors_1.NoSupportedSastFiles;
|
|
27270
27304
|
const noSupportedIaCFiles = error.code === types_1.IaCErrorCodes.NoFilesToScanError;
|
|
27271
27305
|
const noSupportedProjectsDetected = noSupportedManifestsFound || noSupportedSastFiles || noSupportedIaCFiles;
|
|
27272
27306
|
if (noSupportedProjectsDetected) {
|
|
27273
|
-
exitCode = EXIT_CODES.NO_SUPPORTED_PROJECTS_DETECTED;
|
|
27307
|
+
exitCode = exit_codes_1.EXIT_CODES.NO_SUPPORTED_PROJECTS_DETECTED;
|
|
27274
27308
|
}
|
|
27275
27309
|
const vulnsFound = error.code === 'VULNS';
|
|
27276
27310
|
if (vulnsFound) {
|
|
27277
27311
|
// this isn't a bad command, so we won't record it as such
|
|
27278
27312
|
command = args.command;
|
|
27279
|
-
exitCode = EXIT_CODES.VULNS_FOUND;
|
|
27313
|
+
exitCode = exit_codes_1.EXIT_CODES.VULNS_FOUND;
|
|
27280
27314
|
}
|
|
27281
27315
|
if (args.options.debug && !args.options.json) {
|
|
27282
27316
|
const output = vulnsFound ? error.message : error.stack;
|
|
@@ -27365,7 +27399,7 @@ function checkRuntime() {
|
|
|
27365
27399
|
console.error(`Node.js version ${process.versions.node} is an unsupported Node.js ` +
|
|
27366
27400
|
`runtime! Supported runtime range is '${runtime.supportedRange}'`);
|
|
27367
27401
|
console.error('Please upgrade your Node.js runtime. The last version of Snyk CLI that supports Node.js v8 is v1.454.0.');
|
|
27368
|
-
process.exit(EXIT_CODES.ERROR);
|
|
27402
|
+
process.exit(exit_codes_1.EXIT_CODES.ERROR);
|
|
27369
27403
|
}
|
|
27370
27404
|
}
|
|
27371
27405
|
// Throw error if user specifies package file name as part of path,
|
|
@@ -27390,7 +27424,7 @@ async function main() {
|
|
|
27390
27424
|
checkRuntime();
|
|
27391
27425
|
let res;
|
|
27392
27426
|
let failed = false;
|
|
27393
|
-
let exitCode = EXIT_CODES.ERROR;
|
|
27427
|
+
let exitCode = exit_codes_1.EXIT_CODES.ERROR;
|
|
27394
27428
|
try {
|
|
27395
27429
|
modes_1.modeValidation(globalArgs);
|
|
27396
27430
|
// TODO: fix this, we do transformation to options and teh type doesn't reflect it
|
|
@@ -27457,6 +27491,7 @@ async function main() {
|
|
|
27457
27491
|
}
|
|
27458
27492
|
return res;
|
|
27459
27493
|
}
|
|
27494
|
+
exports.main = main;
|
|
27460
27495
|
function validateUnsupportedOptionCombinations(options) {
|
|
27461
27496
|
const unsupportedAllProjectsCombinations = {
|
|
27462
27497
|
'project-name': 'project-name',
|
|
@@ -27567,11 +27602,6 @@ function validateOutputFile(options, outputType, error) {
|
|
|
27567
27602
|
throw error;
|
|
27568
27603
|
}
|
|
27569
27604
|
}
|
|
27570
|
-
main().catch((e) => {
|
|
27571
|
-
console.error('Something unexpected went wrong: ', e.stack);
|
|
27572
|
-
console.error('Exit code: ' + EXIT_CODES.ERROR);
|
|
27573
|
-
process.exit(EXIT_CODES.ERROR);
|
|
27574
|
-
});
|
|
27575
27605
|
|
|
27576
27606
|
|
|
27577
27607
|
/***/ }),
|
|
@@ -30229,6 +30259,80 @@ var SupportedCliCommands;
|
|
|
30229
30259
|
})(SupportedCliCommands = exports.SupportedCliCommands || (exports.SupportedCliCommands = {}));
|
|
30230
30260
|
|
|
30231
30261
|
|
|
30262
|
+
/***/ }),
|
|
30263
|
+
|
|
30264
|
+
/***/ 89088:
|
|
30265
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
30266
|
+
|
|
30267
|
+
"use strict";
|
|
30268
|
+
|
|
30269
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
30270
|
+
exports.callHandlingUnexpectedErrors = void 0;
|
|
30271
|
+
/**
|
|
30272
|
+
* Ensures a given function does not throw any errors, including unexpected ones
|
|
30273
|
+
* outside of its chain of execution.
|
|
30274
|
+
*
|
|
30275
|
+
* This function can only be used once in the same process. If you have multiple
|
|
30276
|
+
* callables needing this, compose them into a single callable.
|
|
30277
|
+
*/
|
|
30278
|
+
async function callHandlingUnexpectedErrors(callable, exitCode) {
|
|
30279
|
+
function handleUnexpectedError(reason) {
|
|
30280
|
+
console.error('Something unexpected went wrong:', reason);
|
|
30281
|
+
console.error('Exit code:', exitCode);
|
|
30282
|
+
process.exit(exitCode);
|
|
30283
|
+
}
|
|
30284
|
+
/**
|
|
30285
|
+
* As the only point we'll know if a given callable has unexpected errors is
|
|
30286
|
+
* when NodeJS exits, we can't handle unexpected errors for more than one
|
|
30287
|
+
* callable. We'll never know which callable an error came from.
|
|
30288
|
+
*/
|
|
30289
|
+
if (process.listenerCount('uncaughtException') > 1) {
|
|
30290
|
+
handleUnexpectedError(new Error('Cannot handle unexpected errors for more than one callable.'));
|
|
30291
|
+
}
|
|
30292
|
+
process.on('uncaughtException', handleUnexpectedError);
|
|
30293
|
+
/**
|
|
30294
|
+
* Since Node 15, 'unhandledRejection' without a handler causes an
|
|
30295
|
+
* 'uncaughtException'. However, we also support Node 14 (as of writing)
|
|
30296
|
+
* which doesn't have that behaviour. So we still need this handler for now.
|
|
30297
|
+
*/
|
|
30298
|
+
process.on('unhandledRejection', handleUnexpectedError);
|
|
30299
|
+
try {
|
|
30300
|
+
await callable();
|
|
30301
|
+
}
|
|
30302
|
+
catch (e) {
|
|
30303
|
+
handleUnexpectedError(e);
|
|
30304
|
+
}
|
|
30305
|
+
/**
|
|
30306
|
+
* Do NOT remove any 'uncaughtException' and 'unhandledRejection' handlers.
|
|
30307
|
+
* It may seem like we should after callable has done its thing. However,
|
|
30308
|
+
* there's never a point when everything's "done". There's no guarantee that
|
|
30309
|
+
* a callable hasn't created a chain of execution outside of its chain which
|
|
30310
|
+
* might trigger an unexpected error.
|
|
30311
|
+
*
|
|
30312
|
+
* For example, we want to avoid this scenario:
|
|
30313
|
+
*
|
|
30314
|
+
* - Add Handler L for 'uncaughtException' and 'unhandledRejection'
|
|
30315
|
+
* - Call Function A
|
|
30316
|
+
* - Function A calls Function B, which returns Promise P.
|
|
30317
|
+
* - Function A does not await Promise P
|
|
30318
|
+
* - Function A returns.
|
|
30319
|
+
* - Remove Handler L. <- Don't do this! Otherwise...
|
|
30320
|
+
* - Some time passes...
|
|
30321
|
+
* - Promise P rejects.
|
|
30322
|
+
* - NodeJS has nothing left to execute.
|
|
30323
|
+
* - NodeJS gathers all unhandled rejected promises.
|
|
30324
|
+
* - There are no 'unhandledRejection' handlers.
|
|
30325
|
+
* - For Node 15 and above:
|
|
30326
|
+
* - NodeJS triggers 'uncaughtException'
|
|
30327
|
+
* - There are no 'uncaughtException' handlers.
|
|
30328
|
+
* - NodeJS defaults to Exit Code 1. <- We want a different exit code.
|
|
30329
|
+
* - For Node 14 and below:
|
|
30330
|
+
* - NodeJS logs a warning. <- We want the same behaviour across versions.
|
|
30331
|
+
*/
|
|
30332
|
+
}
|
|
30333
|
+
exports.callHandlingUnexpectedErrors = callHandlingUnexpectedErrors;
|
|
30334
|
+
|
|
30335
|
+
|
|
30232
30336
|
/***/ }),
|
|
30233
30337
|
|
|
30234
30338
|
/***/ 28137:
|