Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 0f10a81

Browse files
Merge pull request #997 from telerik/milanov/fix-error-handling-in-hooks-execution
Fix the error handling in hooks execution
2 parents 99ae8cc + 8549908 commit 0f10a81

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

services/hooks-service.ts

+19-22
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,25 @@ export class HooksService implements IHooksService {
128128
let maybePromise = this.$injector.resolve(hookEntryPoint, hookArguments);
129129
if (maybePromise) {
130130
this.$logger.trace('Hook promises to signal completion');
131-
await new Promise((resolve, reject) => {
132-
maybePromise.then(
133-
resolve,
134-
(err: any) => {
135-
if (_.isBoolean(err.stopExecution) && err.errorAsWarning === true) {
136-
this.$logger.warn(err.message);
137-
resolve();
138-
} else {
139-
reject(err);
140-
}
141-
});
142-
});
143-
144-
}
145-
this.$logger.trace('Hook completed');
146-
} else {
147-
let environment = this.prepareEnvironment(hook.fullPath);
148-
this.$logger.trace("Executing %s hook at location %s with environment ", hookName, hook.fullPath, environment);
149-
150-
let output = await this.$childProcess.spawnFromEvent(command, [hook.fullPath], "close", environment, { throwError: false });
151-
if (output.exitCode !== 0) {
152-
throw new Error(output.stdout + output.stderr);
131+
try {
132+
await maybePromise;
133+
} catch (err) {
134+
if (err && _.isBoolean(err.stopExecution) && err.errorAsWarning === true) {
135+
this.$logger.warn(err.message || err);
136+
} else {
137+
throw err || new Error(`Failed to execute hook: ${hook.fullPath}.`);
138+
}
139+
}
140+
141+
this.$logger.trace('Hook completed');
142+
} else {
143+
let environment = this.prepareEnvironment(hook.fullPath);
144+
this.$logger.trace("Executing %s hook at location %s with environment ", hookName, hook.fullPath, environment);
145+
146+
let output = await this.$childProcess.spawnFromEvent(command, [hook.fullPath], "close", environment, { throwError: false });
147+
if (output.exitCode !== 0) {
148+
throw new Error(output.stdout + output.stderr);
149+
}
153150
}
154151
}
155152
}

0 commit comments

Comments
 (0)