feat(up): serialize errors before passing them to storage plugins

This commit is contained in:
Joakim Carlstein 2023-12-08 09:39:27 +01:00
parent 3b2b21f729
commit c1d55978d7
7 changed files with 43 additions and 26 deletions

View file

@ -7,8 +7,18 @@ import {
type EmigrateStorage,
type LoaderPlugin,
type StringOrModule,
type SerializedError,
} from './types.js';
export const serializeError = (error: Error): SerializedError => {
return {
name: error.name,
message: error.message,
stack: error.stack,
cause: error.cause instanceof Error ? serializeError(error.cause) : error.cause,
};
};
export const isGeneratorPlugin = (plugin: any): plugin is GeneratorPlugin => {
if (!plugin || typeof plugin !== 'object') {
return false;