feat(up): serialize errors before passing them to storage plugins
This commit is contained in:
parent
3b2b21f729
commit
c1d55978d7
7 changed files with 43 additions and 26 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -4,11 +4,18 @@ export type StringOrModule<T> = string | T | (() => Awaitable<T>) | (() => Await
|
|||
|
||||
export type MigrationStatus = 'failed' | 'done' | 'pending';
|
||||
|
||||
export type SerializedError = {
|
||||
name: string;
|
||||
message: string;
|
||||
stack?: string;
|
||||
cause?: unknown;
|
||||
};
|
||||
|
||||
export type MigrationHistoryEntry = {
|
||||
name: string;
|
||||
status: MigrationStatus;
|
||||
date: Date;
|
||||
error?: unknown;
|
||||
error?: SerializedError;
|
||||
};
|
||||
|
||||
export type Storage = {
|
||||
|
|
@ -66,7 +73,7 @@ export type Storage = {
|
|||
* @param migration The name of the migration that should be marked as failed.
|
||||
* @param error The error that caused the migration to fail.
|
||||
*/
|
||||
onError(migration: MigrationMetadataFinished, error: Error): Promise<void>;
|
||||
onError(migration: MigrationMetadataFinished, error: SerializedError): Promise<void>;
|
||||
};
|
||||
|
||||
export type EmigrateStorage = {
|
||||
|
|
@ -142,7 +149,7 @@ export type MigrationMetadata = {
|
|||
export type MigrationMetadataFinished = MigrationMetadata & {
|
||||
status: MigrationStatus | 'skipped';
|
||||
duration: number;
|
||||
error?: Error;
|
||||
error?: SerializedError;
|
||||
};
|
||||
|
||||
export type LoaderPlugin = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue