Skip to content

Commit 802df40

Browse files
authored
feat: allow async serviceErrorHandler method (#1158)
closes #1157
2 parents 8372761 + 886be2d commit 802df40

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.changeset/late-snakes-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'nest-commander': minor
3+
---
4+
5+
feat: allow async `serviceErrorHandler` method

packages/nest-commander/src/command-factory.interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Help, OutputConfiguration } from 'commander';
44
import type { CompletionFactoryOptions } from './completion.factory.interface';
55

66
export type ErrorHandler = (err: Error) => void;
7+
export type ServiceErrorHandler = (err: Error) => PromiseLike<void> | void;
78
export type NestLogger = LoggerService | LogLevel[] | false;
89

910
export interface DefinedCommandFactoryRunOptions
@@ -18,7 +19,7 @@ export interface CommandFactoryRunOptions
1819
errorHandler?: ErrorHandler;
1920
usePlugins?: boolean;
2021
cliName?: string;
21-
serviceErrorHandler?: ErrorHandler;
22+
serviceErrorHandler?: ServiceErrorHandler;
2223
enablePositionalOptions?: boolean;
2324
enablePassThroughOptions?: boolean;
2425
outputConfiguration?: OutputConfiguration;

packages/nest-commander/src/command-runner.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ ${cliPluginError(
6161
this.commander.exitOverride(this.options.errorHandler);
6262
}
6363
if (!this.options.serviceErrorHandler) {
64-
this.options.serviceErrorHandler = (err: Error) =>
64+
this.options.serviceErrorHandler = (err: Error) => {
6565
process.stderr.write(err.toString());
66+
};
6667
}
6768
if (this.options.outputConfiguration) {
6869
this.commander.configureOutput(this.options.outputConfiguration);

0 commit comments

Comments
 (0)