mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix: Fix task runner error propagation (no-changelog) (#11291)
This commit is contained in:
parent
d2266c93a7
commit
d330b6b94a
|
@ -758,17 +758,20 @@ describe('JsTaskRunner', () => {
|
||||||
|
|
||||||
await runner.receivedSettings(taskId, task.settings);
|
await runner.receivedSettings(taskId, task.settings);
|
||||||
|
|
||||||
expect(sendSpy).toHaveBeenCalledWith(
|
expect(sendSpy).toHaveBeenCalled();
|
||||||
JSON.stringify({
|
const calledWith = sendSpy.mock.calls[0][0] as string;
|
||||||
type: 'runner:taskerror',
|
expect(typeof calledWith).toBe('string');
|
||||||
taskId,
|
const calledObject = JSON.parse(calledWith);
|
||||||
error: {
|
expect(calledObject).toEqual({
|
||||||
message: 'unknown is not defined [line 1]',
|
type: 'runner:taskerror',
|
||||||
description: 'ReferenceError',
|
taskId,
|
||||||
lineNumber: 1,
|
error: {
|
||||||
},
|
stack: expect.any(String),
|
||||||
}),
|
message: 'unknown is not defined [line 1]',
|
||||||
);
|
description: 'ReferenceError',
|
||||||
}, 1000);
|
lineNumber: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -42,6 +42,7 @@ describe('ExecutionError', () => {
|
||||||
|
|
||||||
expect(JSON.stringify(executionError)).toBe(
|
expect(JSON.stringify(executionError)).toBe(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
stack: defaultStack,
|
||||||
message: 'a.unknown is not a function [line 2, for item 1]',
|
message: 'a.unknown is not a function [line 2, for item 1]',
|
||||||
description: 'TypeError',
|
description: 'TypeError',
|
||||||
itemIndex: 1,
|
itemIndex: 1,
|
||||||
|
|
|
@ -1,3 +1,24 @@
|
||||||
|
/**
|
||||||
|
* Makes the given error's `message` and `stack` properties enumerable
|
||||||
|
* so they can be serialized with JSON.stringify
|
||||||
|
*/
|
||||||
|
export function makeSerializable(error: Error) {
|
||||||
|
Object.defineProperties(error, {
|
||||||
|
message: {
|
||||||
|
value: error.message,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true,
|
||||||
|
},
|
||||||
|
stack: {
|
||||||
|
value: error.stack,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error that has its message property serialized as well. Used to transport
|
* Error that has its message property serialized as well. Used to transport
|
||||||
* errors over the wire.
|
* errors over the wire.
|
||||||
|
@ -6,16 +27,6 @@ export abstract class SerializableError extends Error {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
||||||
// So it is serialized as well
|
makeSerializable(this);
|
||||||
this.makeMessageEnumerable();
|
|
||||||
}
|
|
||||||
|
|
||||||
private makeMessageEnumerable() {
|
|
||||||
Object.defineProperty(this, 'message', {
|
|
||||||
value: this.message,
|
|
||||||
enumerable: true, // This makes the message property enumerable
|
|
||||||
writable: true,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import { type Task, TaskRunner } from '@/task-runner';
|
||||||
|
|
||||||
import { isErrorLike } from './errors/error-like';
|
import { isErrorLike } from './errors/error-like';
|
||||||
import { ExecutionError } from './errors/execution-error';
|
import { ExecutionError } from './errors/execution-error';
|
||||||
|
import { makeSerializable } from './errors/serializable-error';
|
||||||
import type { RequireResolver } from './require-resolver';
|
import type { RequireResolver } from './require-resolver';
|
||||||
import { createRequireResolver } from './require-resolver';
|
import { createRequireResolver } from './require-resolver';
|
||||||
import { validateRunForAllItemsOutput, validateRunForEachItemOutput } from './result-validation';
|
import { validateRunForAllItemsOutput, validateRunForEachItemOutput } from './result-validation';
|
||||||
|
@ -323,7 +324,7 @@ export class JsTaskRunner extends TaskRunner {
|
||||||
|
|
||||||
private toExecutionErrorIfNeeded(error: unknown): Error {
|
private toExecutionErrorIfNeeded(error: unknown): Error {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
return error;
|
return makeSerializable(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isErrorLike(error)) {
|
if (isErrorLike(error)) {
|
||||||
|
|
|
@ -21,10 +21,6 @@ export class WrappedExecutionError extends ApplicationError {
|
||||||
|
|
||||||
private copyErrorProperties(error: WrappableError) {
|
private copyErrorProperties(error: WrappableError) {
|
||||||
for (const key of Object.getOwnPropertyNames(error)) {
|
for (const key of Object.getOwnPropertyNames(error)) {
|
||||||
if (key === 'message' || key === 'stack') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
this[key] = error[key];
|
this[key] = error[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue