9ff4c0dbd5
* Setup project-wide prettier * Remove old workspace file * Remove old debugging directives * New top-level .prettierignore * Updated Prettier config settings * Contrubuting guide: Fix for some bad code blocks * Added more ignores * Improved the format script command * printWidth set to 100 * Formatted entire repo (pnpm run format)
20 lines
609 B
TypeScript
20 lines
609 B
TypeScript
import { ErrorWithStack, ErrorWithStackSchema } from "@trigger.dev/core";
|
|
|
|
export function formatError(error: ErrorWithStack, style: "short" | "long" = "short"): string {
|
|
if (style === "short") {
|
|
return error.name ? `${error.name}: ${error.message}` : error.message;
|
|
}
|
|
|
|
return formatError(error, "short") + "\n" + error.stack;
|
|
}
|
|
|
|
export function formatUnknownError(error: unknown, style: "short" | "long" = "short"): string {
|
|
const parsedError = ErrorWithStackSchema.safeParse(error);
|
|
|
|
if (parsedError.success) {
|
|
return formatError(parsedError.data, style);
|
|
}
|
|
|
|
return "Unknown error";
|
|
}
|