Skip to content

fix: show the actual error when hook fails #4808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/common/services/hooks-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`);
Expand All @@ -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}.`);
}
}
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
});
Expand Down