-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: compose error catalog errors in TS custom errors
- Loading branch information
Showing
69 changed files
with
331 additions
and
113 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { CustomError } from '../../../../../lib/errors'; | |
import { getErrorStringCode } from './error-utils'; | ||
import { IacFileInDirectory } from '../../../../../lib/types'; | ||
import { SEVERITIES } from '../../../../../lib/snyk-test/common'; | ||
import { CLI } from '@snyk/error-catalog-nodejs-public'; | ||
|
||
export async function scanFiles(parsedFiles: Array<IacFileParsed>): Promise<{ | ||
scannedFiles: IacFileScanResult[]; | ||
|
@@ -165,19 +166,23 @@ class PolicyEngine { | |
|
||
export class FailedToBuildPolicyEngine extends CustomError { | ||
constructor(message?: string) { | ||
super(message || 'Failed to build policy engine'); | ||
const msg = message || 'Failed to build policy engine'; | ||
super(msg); | ||
this.code = IaCErrorCodes.FailedToBuildPolicyEngine; | ||
this.strCode = getErrorStringCode(this.code); | ||
this.userMessage = | ||
'We were unable to run the test. Please run the command again with the `-d` flag and contact [email protected] with the contents of the output'; | ||
this.errorCatalog = new CLI.GeneralIACFailureError(msg); | ||
} | ||
} | ||
export class FailedToExecutePolicyEngine extends CustomError { | ||
constructor(message?: string) { | ||
super(message || 'Failed to execute policy engine'); | ||
const msg = message || 'Failed to execute policy engine'; | ||
super(msg); | ||
this.code = IaCErrorCodes.FailedToExecutePolicyEngine; | ||
this.strCode = getErrorStringCode(this.code); | ||
this.userMessage = | ||
'We were unable to run the test. Please run the command again with the `-d` flag and contact [email protected] with the contents of the output'; | ||
this.errorCatalog = new CLI.GeneralIACFailureError(msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { getAuthHeader } from '../../../../../../lib/api-token'; | |
import { makeRequest } from '../../../../../../lib/request'; | ||
import { CustomError } from '../../../../../../lib/errors'; | ||
import { getErrorStringCode } from '../error-utils'; | ||
import { CLI } from '@snyk/error-catalog-nodejs-public'; | ||
|
||
export function getIacOrgSettings( | ||
publicOrgId?: string, | ||
|
@@ -36,10 +37,12 @@ export function getIacOrgSettings( | |
|
||
export class FailedToGetIacOrgSettingsError extends CustomError { | ||
constructor(message?: string) { | ||
const usrMsg = | ||
'We failed to fetch your organization settings, including custom severity overrides for infrastructure-as-code policies. Please run the command again with the `-d` flag and contact [email protected] with the contents of the output.'; | ||
super(message || 'Failed to fetch IaC organization settings'); | ||
this.code = IaCErrorCodes.FailedToGetIacOrgSettingsError; | ||
this.strCode = getErrorStringCode(this.code); | ||
this.userMessage = | ||
'We failed to fetch your organization settings, including custom severity overrides for infrastructure-as-code policies. Please run the command again with the `-d` flag and contact [email protected] with the contents of the output.'; | ||
this.userMessage = usrMsg; | ||
this.errorCatalog = new CLI.GeneralIACFailureError(usrMsg); | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
src/cli/commands/test/iac/local-execution/parsers/terraform-file-parser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { IaCErrorCodes } from '../types'; | ||
import { CustomError } from '../../../../../../lib/errors'; | ||
import { getErrorStringCode } from '../error-utils'; | ||
import { CLI } from '@snyk/error-catalog-nodejs-public'; | ||
|
||
export class FailedToParseTerraformFileError extends CustomError { | ||
public filename: string; | ||
constructor(filename: string) { | ||
const usrMsg = `We were unable to parse the Terraform file "${filename}", please ensure it is valid HCL2. This can be done by running it through the 'terraform validate' command.`; | ||
super('Failed to parse Terraform file'); | ||
this.code = IaCErrorCodes.FailedToParseTerraformFileError; | ||
this.strCode = getErrorStringCode(this.code); | ||
this.filename = filename; | ||
this.userMessage = `We were unable to parse the Terraform file "${filename}", please ensure it is valid HCL2. This can be done by running it through the 'terraform validate' command.`; | ||
this.userMessage = usrMsg; | ||
this.errorCatalog = new CLI.GeneralIACFailureError(usrMsg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import { | |
import { CustomError } from '../../../../../../lib/errors'; | ||
import { getErrorStringCode } from '../error-utils'; | ||
import { IacProjectType } from '../../../../../../lib/iac/constants'; | ||
import { CLI } from '@snyk/error-catalog-nodejs-public'; | ||
|
||
function terraformPlanReducer( | ||
scanInput: TerraformScanInput, | ||
|
@@ -183,12 +184,14 @@ export function tryParsingTerraformPlan( | |
// This error is due to the complex reduction logic, so it catches scenarios we might have not covered. | ||
export class FailedToExtractResourcesInTerraformPlanError extends CustomError { | ||
constructor(message?: string) { | ||
const usrMsg = | ||
'We failed to extract resource changes from the Terraform plan file, please contact [email protected], if possible with a redacted version of the file'; | ||
super( | ||
message || 'Failed to extract resources from Terraform plan JSON file', | ||
); | ||
this.code = IaCErrorCodes.FailedToExtractResourcesInTerraformPlanError; | ||
this.strCode = getErrorStringCode(this.code); | ||
this.userMessage = | ||
'We failed to extract resource changes from the Terraform plan file, please contact [email protected], if possible with a redacted version of the file'; | ||
this.userMessage = usrMsg; | ||
this.errorCatalog = new CLI.GeneralIACFailureError(usrMsg); | ||
} | ||
} |
Oops, something went wrong.