Skip to content

Commit

Permalink
dev: Move CheckFailed Error into its own file. (#1663)
Browse files Browse the repository at this point in the history
* dev: Move CheckFailed Error into its own file.

* Update bin.js
  • Loading branch information
Jason3S committed Sep 8, 2021
1 parent bc5d52d commit f464a81
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/cspell/bin.js
Expand Up @@ -8,6 +8,8 @@ const program = require('commander');
app.run(program, process.argv).catch((e) => {
if (!(e instanceof program.CommanderError) && !(e instanceof app.CheckFailed)) {
console.log(e);
// It is possible an explicit exit code was set, use it if it was.
process.exitCode = process.exitCode || 1;
}
if (e instanceof app.CheckFailed) {
process.exitCode = e.exitCode;
Expand Down
9 changes: 3 additions & 6 deletions packages/cspell/src/app.ts
Expand Up @@ -17,6 +17,9 @@ import { tableToLines } from './util/table';
import { Emitters, isProgressFileComplete, MessageType, ProgressItem, Issue } from './emitters';
import { isSpellingDictionaryLoadError, SpellingDictionaryLoadError, ImportError } from 'cspell-lib';
import { emitTraceResults } from './traceEmitter';
import { CheckFailed } from './util/errors';

export { CheckFailed } from './util/errors';

interface Options extends CSpellApplicationOptions {
legacy?: boolean;
Expand Down Expand Up @@ -409,9 +412,3 @@ class TS extends Array<string> {
function template(s: string): TemplateStringsArray {
return new TS(s);
}

export class CheckFailed extends Error {
constructor(message: string, readonly exitCode: number = 1) {
super(message);
}
}
11 changes: 11 additions & 0 deletions packages/cspell/src/util/errors.test.ts
@@ -0,0 +1,11 @@
import { CheckFailed } from './errors';

describe('errors', () => {
test.each`
ErrorClass | params
${CheckFailed} | ${['no matches']}
`('new', ({ ErrorClass, params }) => {
const e = new ErrorClass(...params);
expect(e instanceof Error).toBe(true);
});
});
5 changes: 5 additions & 0 deletions packages/cspell/src/util/errors.ts
@@ -0,0 +1,5 @@
export class CheckFailed extends Error {
constructor(message: string, readonly exitCode: number = 1) {
super(message);
}
}

0 comments on commit f464a81

Please sign in to comment.