diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 4947c44..6ea6735 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,11 @@ # vdbs +## 0.0.4 + +### Patch Changes + +- add error handling + ## 0.0.3 ### Patch Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index 313c597..2e8fd0e 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "vdbs", - "version": "0.0.3", + "version": "0.0.4", "description": "Generate migrations from database diagrams", "license": "MIT", "keywords": [ diff --git a/packages/cli/src/commands/add.ts b/packages/cli/src/commands/add.ts index e430798..a6cb650 100644 --- a/packages/cli/src/commands/add.ts +++ b/packages/cli/src/commands/add.ts @@ -11,6 +11,7 @@ import { logger } from "@/utils/logger.js"; import { listCommands } from "@/utils/list-commands.js"; import { showNextSteps } from "@/utils/show-next-steps.js"; import { getSchema } from "@/utils/get-schema.js"; +import { handleError } from "@/utils/handleError.js"; const addArgumentsSchema = z.object({ generation: z.string().optional(), @@ -121,7 +122,7 @@ export const add = new Command() // 4. In order to deploy the migration remotely, user has to do the following... showNextSteps(Boolean(pathFound)); } catch (error) { - console.error(error); + handleError(error); } }); diff --git a/packages/cli/src/utils/handleError.ts b/packages/cli/src/utils/handleError.ts new file mode 100644 index 0000000..d4a3ea9 --- /dev/null +++ b/packages/cli/src/utils/handleError.ts @@ -0,0 +1,16 @@ +import { logger } from "@/utils/logger.js"; + +export function handleError(error: unknown) { + if (typeof error === "string") { + logger.error(error); + process.exit(1); + } + + if (error instanceof Error) { + logger.error(error.message); + process.exit(1); + } + + logger.error("Something went wrong. Please try again."); + process.exit(1); +}