Skip to content

Commit

Permalink
feat: allow async serviceErrorHandler method (#1158)
Browse files Browse the repository at this point in the history
closes #1157
  • Loading branch information
jmcdo29 authored Aug 14, 2024
2 parents 8372761 + 886be2d commit 802df40
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-snakes-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nest-commander': minor
---

feat: allow async `serviceErrorHandler` method
3 changes: 2 additions & 1 deletion packages/nest-commander/src/command-factory.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Help, OutputConfiguration } from 'commander';
import type { CompletionFactoryOptions } from './completion.factory.interface';

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

export interface DefinedCommandFactoryRunOptions
Expand All @@ -18,7 +19,7 @@ export interface CommandFactoryRunOptions
errorHandler?: ErrorHandler;
usePlugins?: boolean;
cliName?: string;
serviceErrorHandler?: ErrorHandler;
serviceErrorHandler?: ServiceErrorHandler;
enablePositionalOptions?: boolean;
enablePassThroughOptions?: boolean;
outputConfiguration?: OutputConfiguration;
Expand Down
3 changes: 2 additions & 1 deletion packages/nest-commander/src/command-runner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ ${cliPluginError(
this.commander.exitOverride(this.options.errorHandler);
}
if (!this.options.serviceErrorHandler) {
this.options.serviceErrorHandler = (err: Error) =>
this.options.serviceErrorHandler = (err: Error) => {
process.stderr.write(err.toString());
};
}
if (this.options.outputConfiguration) {
this.commander.configureOutput(this.options.outputConfiguration);
Expand Down

0 comments on commit 802df40

Please sign in to comment.