n8n/packages/nodes-base/nodes/Code/errors/WrappedExecutionError.ts
Tomi Turtiainen 690138394f
refactor: Re-parent leaf error subclasses to UserError (no-changelog) (#32541)
Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
2026-06-24 10:00:16 +00:00

32 lines
832 B
TypeScript

import { UserError } from 'n8n-workflow';
export type WrappableError = Record<string, unknown>;
/**
* Errors received from the task runner are not instances of Error.
* This class wraps them in an Error instance and makes all their
* properties available.
*/
export class WrappedExecutionError extends UserError {
[key: string]: unknown;
constructor(error: WrappableError) {
const message = typeof error.message === 'string' ? error.message : 'Unknown error';
super(message, {
cause: error,
});
this.copyErrorProperties(error);
}
private copyErrorProperties(error: WrappableError) {
for (const key of Object.getOwnPropertyNames(error)) {
this[key] = error[key];
}
}
}
export function isWrappableError(error: unknown): error is WrappableError {
return typeof error === 'object' && error !== null;
}