import { DatabaseTransportError } from "../database/transport.js"; import { MigrationRunnerError, PostgresMigrationDatabaseError } from "../migrations/index.js"; import { ModuleDiscoveryError, ModuleMigrationDiscoveryError } from "../modules/index.js"; export function reportMigrationCommandError(error: unknown): void { if (error instanceof DatabaseTransportError) { // The message is a fixed string chosen by code; it never carries the connection string, host, // port, credentials, CA material, or the offending mode value, so it is safe to print as-is — // and an operator who misconfigured TLS needs to know that, not "failed unexpectedly". console.error(`[${error.code}] ${error.message}`); return; } if (error instanceof ModuleDiscoveryError) { console.error(error.message); for (const issue of error.issues) { const issuePath = issue.path ? ` (${issue.path})` : ""; console.error(`[${issue.code}] ${issue.moduleDirectory}${issuePath}: ${issue.message}`); } return; } if (error instanceof ModuleMigrationDiscoveryError) { console.error(error.message); for (const issue of error.issues) { const issuePath = issue.path ? ` (${issue.path})` : ""; console.error(`[${issue.code}] ${issue.moduleId}${issuePath}: ${issue.message}`); } return; } if (error instanceof MigrationRunnerError) { console.error(`[${error.code}] ${error.message}`); return; } if ( error instanceof PostgresMigrationDatabaseError && error.code === "POSTGRES_MIGRATION_CONFIGURATION_INVALID" ) { console.error("[MIGRATION_CONFIGURATION_INVALID] Migration configuration is invalid."); return; } console.error("Migration command failed unexpectedly."); }