diff --git a/declarations.d.ts b/declarations.d.ts index f0df54a1..f25c5d6c 100644 --- a/declarations.d.ts +++ b/declarations.d.ts @@ -537,9 +537,9 @@ interface IOpener { } interface IErrors { - fail(formatStr: string, ...args: any[]): void; - fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): void; - failWithoutHelp(message: string, ...args: any[]): void; + fail(formatStr: string, ...args: any[]): never; + fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): never; + failWithoutHelp(message: string, ...args: any[]): never; beginCommand(action: () => Promise, printCommandHelp: () => Promise): Promise; verifyHeap(message: string): void; printCallStack: boolean; diff --git a/errors.ts b/errors.ts index fdf3316e..f5991e68 100644 --- a/errors.ts +++ b/errors.ts @@ -122,7 +122,7 @@ export class Errors implements IErrors { public printCallStack: boolean = false; - public fail(optsOrFormatStr: any, ...args: any[]): void { + public fail(optsOrFormatStr: any, ...args: any[]): never { const argsArray = args || []; let opts = optsOrFormatStr; @@ -146,9 +146,9 @@ export class Errors implements IErrors { throw exception; } - public failWithoutHelp(message: string, ...args: any[]): void { + public failWithoutHelp(message: string, ...args: any[]): never { args.unshift(message); - this.fail({ formatStr: util.format.apply(null, args), suppressCommandHelp: true }); + return this.fail({ formatStr: util.format.apply(null, args), suppressCommandHelp: true }); } public async beginCommand(action: () => Promise, printCommandHelp: () => Promise): Promise { diff --git a/test/unit-tests/common-options.ts b/test/unit-tests/common-options.ts index 1ad8a2d6..aa257410 100644 --- a/test/unit-tests/common-options.ts +++ b/test/unit-tests/common-options.ts @@ -38,12 +38,12 @@ describe("common options", () => { testInjector = createTestInjector(); const errors = new Errors(testInjector); - errors.failWithoutHelp = (message: string, ...args: any[]): void => { + errors.failWithoutHelp = ((message: string, ...args: any[]): void => { isExecutionStopped = true; - }; - errors.fail = (message: string, ...args: any[]): void => { + }); + errors.fail = ((message: string, ...args: any[]): void => { isExecutionStopped = true; - }; + }); testInjector.register("errors", errors); isExecutionStopped = false; diff --git a/test/unit-tests/stubs.ts b/test/unit-tests/stubs.ts index 265d5b21..b53027b1 100644 --- a/test/unit-tests/stubs.ts +++ b/test/unit-tests/stubs.ts @@ -43,14 +43,14 @@ export class CommonLoggerStub implements ILogger { export class ErrorsStub implements IErrors { printCallStack: boolean = false; - fail(formatStr: string, ...args: any[]): void; - fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): void; + fail(formatStr: string, ...args: any[]): never; + fail(opts: { formatStr?: string; errorCode?: number; suppressCommandHelp?: boolean }, ...args: any[]): never; - fail(...args: any[]) { + fail(...args: any[]): never { throw new Error(util.format.apply(null, args)); } - failWithoutHelp(message: string, ...args: any[]): void { + failWithoutHelp(message: string, ...args: any[]): never { throw new Error(message); }