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

@ -1,6 +1,6 @@
import path from 'node:path';
import process from 'node:process';
import { getOrLoadPlugins, getOrLoadReporter, getOrLoadStorage } from '@emigrate/plugin-tools';
import { getOrLoadPlugins, getOrLoadReporter, getOrLoadStorage, serializeError } from '@emigrate/plugin-tools';
import {
type LoaderPlugin,
type MigrationFunction,
@ -219,15 +219,16 @@ export default async function upCommand({
finishedMigrations.push(finishedMigration);
} catch (error) {
const errorInstance = error instanceof Error ? error : new Error(String(error));
const serializedError = serializeError(errorInstance);
const duration = getDuration(start);
const finishedMigration: MigrationMetadataFinished = {
...migration,
status: 'failed',
duration,
error: errorInstance,
error: serializedError,
};
await storage.onError(finishedMigration, errorInstance);
await storage.onError(finishedMigration, serializedError);
await reporter.onMigrationError?.(finishedMigration, errorInstance);
finishedMigrations.push(finishedMigration);