From 786e9fc6a024e2bf0dad08a3596a7ec73ef695b6 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 5 Jul 2019 14:10:19 +0300 Subject: [PATCH] fix: show the actual error when hook fails When hook throws an error, there's no easy way to find exactly what is failing as CLI overwrites the error and its callstack. As it is not trivial solution to stop CLI of doing this, when a hook fails, just log the error with its callstack. We know these errors always lead to stopage of CLI process, so we can safely print them. --- lib/common/services/hooks-service.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/common/services/hooks-service.ts b/lib/common/services/hooks-service.ts index 1362aa9a64..a455e1cdda 100644 --- a/lib/common/services/hooks-service.ts +++ b/lib/common/services/hooks-service.ts @@ -117,7 +117,7 @@ export class HooksService implements IHooksService { this.$logger.trace(`Validating ${hookName} arguments.`); - const invalidArguments = this.validateHookArguments(hookEntryPoint); + const invalidArguments = this.validateHookArguments(hookEntryPoint, hook.fullPath); if (invalidArguments.length) { this.$logger.warn(`${hook.fullPath} will NOT be executed because it has invalid arguments - ${invalidArguments.join(", ").grey}.`); @@ -144,6 +144,8 @@ export class HooksService implements IHooksService { if (err && _.isBoolean(err.stopExecution) && err.errorAsWarning === true) { this.$logger.warn(err.message || err); } else { + // Print the actual error with its callstack, so it is easy to find out which hooks is causing troubles. + this.$logger.error(err); throw err || new Error(`Failed to execute hook: ${hook.fullPath}.`); } } @@ -266,7 +268,7 @@ export class HooksService implements IHooksService { } } - private validateHookArguments(hookConstructor: Function): string[] { + private validateHookArguments(hookConstructor: Function, hookFullPath: string): string[] { const invalidArguments: string[] = []; // We need to annotate the hook in order to have the arguments of the constructor. @@ -278,7 +280,7 @@ export class HooksService implements IHooksService { this.$injector.resolve(argument); } } catch (err) { - this.$logger.trace(`Cannot resolve ${argument}, reason: ${err}`); + this.$logger.trace(`Cannot resolve ${argument} of hook ${hookFullPath}, reason: ${err}`); invalidArguments.push(argument); } });