snyk 1.970.0 → 1.971.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.
@@ -3255,6 +3255,62 @@ function convertIacResultToScanResult(iacResult, policy, gitTarget, options) {
3255
3255
  exports.convertIacResultToScanResult = convertIacResultToScanResult;
3256
3256
 
3257
3257
 
3258
+ /***/ }),
3259
+
3260
+ /***/ 87198:
3261
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3262
+
3263
+ "use strict";
3264
+
3265
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3266
+ exports.SnykIacTestError = exports.getErrorUserMessage = void 0;
3267
+ const error_utils_1 = __webpack_require__(36401);
3268
+ const types_1 = __webpack_require__(94820);
3269
+ const errors_1 = __webpack_require__(55191);
3270
+ const defaultUserMessage = 'Your test request could not be completed. Please run the command again with the `-d` flag and contact support@snyk.io with the contents of the output';
3271
+ const snykIacTestErrorsUserMessages = {
3272
+ NoPaths: 'No valid paths were provided',
3273
+ CwdTraversal: 'Running the scan from outside of the current working directory is not supported',
3274
+ NoBundle: 'A rules bundle were not provided',
3275
+ OpenBundle: "The Snyk CLI couldn't open the rules bundle",
3276
+ Scan: defaultUserMessage,
3277
+ UnableToRecognizeInputType: 'Input type was not recognized',
3278
+ UnsupportedInputType: 'Input type is not supported',
3279
+ UnableToResolveLocation: 'Could not resolve location of resource/attribute',
3280
+ UnrecognizedFileExtension: 'Unrecognized file extension',
3281
+ FailedToParseInput: 'Failed to parse input',
3282
+ InvalidInput: 'Invalid input',
3283
+ UnableToReadFile: 'Unable to read file',
3284
+ UnableToReadDir: 'Unable to read directory',
3285
+ UnableToReadStdin: 'Unable to read stdin',
3286
+ FailedToLoadRegoAPI: defaultUserMessage,
3287
+ FailedToLoadRules: defaultUserMessage,
3288
+ FailedToCompile: defaultUserMessage,
3289
+ UnableToReadPath: 'Unable to read path',
3290
+ NoLoadableInput: "The Snyk CLI couldn't find any valid IaC configuration files to scan",
3291
+ };
3292
+ function getErrorUserMessage(code) {
3293
+ if (code < 2000 || code >= 3000) {
3294
+ return 'INVALID_SNYK_IAC_TEST_ERROR';
3295
+ }
3296
+ const errorName = types_1.IaCErrorCodes[code];
3297
+ if (!errorName) {
3298
+ return 'INVALID_IAC_ERROR';
3299
+ }
3300
+ return snykIacTestErrorsUserMessages[errorName];
3301
+ }
3302
+ exports.getErrorUserMessage = getErrorUserMessage;
3303
+ class SnykIacTestError extends errors_1.CustomError {
3304
+ constructor(error) {
3305
+ super(error.message);
3306
+ this.code = error.code;
3307
+ this.strCode = error_utils_1.getErrorStringCode(this.code);
3308
+ this.userMessage = getErrorUserMessage(this.code);
3309
+ }
3310
+ }
3311
+ exports.SnykIacTestError = SnykIacTestError;
3312
+
3313
+
3258
3314
  /***/ }),
3259
3315
 
3260
3316
  /***/ 17152:
@@ -3498,8 +3554,14 @@ const types_1 = __webpack_require__(55246);
3498
3554
  const iac_output_1 = __webpack_require__(68145);
3499
3555
  const iac_output_2 = __webpack_require__(68145);
3500
3556
  const json_2 = __webpack_require__(27019);
3557
+ const errors_1 = __webpack_require__(87198);
3501
3558
  function buildOutput({ scanResult, testSpinner, projectName, orgSettings, options, }) {
3502
- testSpinner === null || testSpinner === void 0 ? void 0 : testSpinner.succeed(iac_output_1.spinnerSuccessMessage);
3559
+ if (scanResult.results) {
3560
+ testSpinner === null || testSpinner === void 0 ? void 0 : testSpinner.succeed(iac_output_1.spinnerSuccessMessage);
3561
+ }
3562
+ else {
3563
+ testSpinner === null || testSpinner === void 0 ? void 0 : testSpinner.stop();
3564
+ }
3503
3565
  let response = '';
3504
3566
  const testData = iac_output_2.formatSnykIacTestTestData(scanResult.results);
3505
3567
  response +=
@@ -3507,6 +3569,21 @@ function buildOutput({ scanResult, testSpinner, projectName, orgSettings, option
3507
3569
  iac_output_1.getIacDisplayedIssues(testData.resultsBySeverity, {
3508
3570
  shouldShowLineNumbers: true,
3509
3571
  });
3572
+ if (scanResult.errors) {
3573
+ const testFailures = scanResult.errors.map((error) => {
3574
+ var _a;
3575
+ const formattedError = new errors_1.SnykIacTestError(error);
3576
+ // If we received an error without a path it means that the scan failed
3577
+ if (!((_a = error === null || error === void 0 ? void 0 : error.fields) === null || _a === void 0 ? void 0 : _a.path)) {
3578
+ throw formattedError;
3579
+ }
3580
+ return {
3581
+ filePath: error.fields.path,
3582
+ failureReason: formattedError.userMessage,
3583
+ };
3584
+ });
3585
+ response += os_1.EOL.repeat(2) + iac_output_1.formatIacTestFailures(testFailures);
3586
+ }
3510
3587
  const jsonData = json_2.jsonStringifyLargeObject(json_1.convertEngineToJsonResults({
3511
3588
  results: scanResult,
3512
3589
  projectName,