feat(plugin-tools): improve error serialization and let each storage plugin serialize errors themselves

This commit is contained in:
Joakim Carlstein 2023-12-12 15:32:58 +01:00
parent 09181f284d
commit a79f8e8e37
6 changed files with 29 additions and 10 deletions

View file

@ -11,12 +11,16 @@ import {
} from './types.js';
export const serializeError = (error: Error): SerializedError => {
return {
const properties: Record<string, unknown> = {
name: error.name,
message: error.message,
stack: error.stack,
cause: error.cause instanceof Error ? serializeError(error.cause) : error.cause,
};
for (const key of Object.getOwnPropertyNames(error)) {
const value = error[key as keyof Error];
properties[key] = value instanceof Error ? serializeError(value) : value;
}
return properties as SerializedError;
};
export const isGeneratorPlugin = (plugin: any): plugin is GeneratorPlugin => {