Skip to content

Commit

Permalink
add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
xavimondev committed Apr 21, 2024
1 parent 7e6b693 commit 7c46f96
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# vdbs

## 0.0.4

### Patch Changes

- add error handling

## 0.0.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vdbs",
"version": "0.0.3",
"version": "0.0.4",
"description": "Generate migrations from database diagrams",
"license": "MIT",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
}
});

Expand Down
16 changes: 16 additions & 0 deletions packages/cli/src/utils/handleError.ts
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 7c46f96

Please sign in to comment.