Skip to content

Commit

Permalink
fix: Propagate plugin error to users
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Jul 30, 2019
1 parent 64667eb commit 38b15dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/lib/errors/failed-to-run-test-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {CustomError} from './custom-error';

export class FailedToRunTestError extends CustomError {
private static ERROR_MESSAGE: string =
'Failed to run a test';

constructor(userMessage, errorCode?) {
const code = errorCode || 500;
super(userMessage || FailedToRunTestError.ERROR_MESSAGE);
this.code = errorCode || code;
this.userMessage = userMessage || FailedToRunTestError.ERROR_MESSAGE;
}
}
1 change: 1 addition & 0 deletions src/lib/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export {InternalServerError} from './internal-server-error';
export {FailedToGetVulnerabilitiesError} from './failed-to-get-vulnerabilities-error';
export {UnsupportedFeatureFlagError} from './unsupported-feature-flag-error';
export {UnsupportedPackageManagerError} from './unsupported-package-manager-error';
export {FailedToRunTestError} from './failed-to-run-test-error';
6 changes: 5 additions & 1 deletion src/lib/snyk-test/run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
NoSupportedManifestsFoundError,
InternalServerError,
FailedToGetVulnerabilitiesError,
FailedToRunTestError,
} from '../errors';
import { maybePrintDeps } from '../print-deps';
import { SupportedPackageManagers } from '../package-managers';
Expand Down Expand Up @@ -147,7 +148,10 @@ async function runTest(packageManager: SupportedPackageManagers,
throw NoSupportedManifestsFoundError([root]);
}

throw err;
throw new FailedToRunTestError(
err.userMessage || err.message || `Failed to test ${packageManager} project`,
err.code,
);
} finally {
spinner.clear(spinnerLbl)();
}
Expand Down

0 comments on commit 38b15dc

Please sign in to comment.