summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/hip-mugs-know.md5
-rw-r--r--packages/db/src/core/cli/commands/execute/index.ts17
-rw-r--r--packages/db/src/core/errors.ts13
3 files changed, 28 insertions, 7 deletions
diff --git a/.changeset/hip-mugs-know.md b/.changeset/hip-mugs-know.md
new file mode 100644
index 000000000..321c3e494
--- /dev/null
+++ b/.changeset/hip-mugs-know.md
@@ -0,0 +1,5 @@
+---
+"@astrojs/db": patch
+---
+
+Add success and error logs to `astro db execute` command
diff --git a/packages/db/src/core/cli/commands/execute/index.ts b/packages/db/src/core/cli/commands/execute/index.ts
index 7fd126182..606245bbe 100644
--- a/packages/db/src/core/cli/commands/execute/index.ts
+++ b/packages/db/src/core/cli/commands/execute/index.ts
@@ -4,7 +4,8 @@ import type { Arguments } from 'yargs-parser';
import {
FILE_NOT_FOUND_ERROR,
MISSING_EXECUTE_PATH_ERROR,
- SEED_DEFAULT_EXPORT_ERROR,
+ EXEC_DEFAULT_EXPORT_ERROR,
+ EXEC_ERROR,
} from '../../../errors.js';
import {
getLocalVirtualModContents,
@@ -13,6 +14,8 @@ import {
import { bundleFile, importBundledFile } from '../../../load-file.js';
import { getManagedAppTokenOrExit } from '../../../tokens.js';
import { type DBConfig } from '../../../types.js';
+import { LibsqlError } from '@libsql/client';
+import { green } from 'kleur/colors';
export async function cmd({
astroConfig,
@@ -54,8 +57,16 @@ export async function cmd({
const mod = await importBundledFile({ code, root: astroConfig.root });
if (typeof mod.default !== 'function') {
- console.error(SEED_DEFAULT_EXPORT_ERROR);
+ console.error(EXEC_DEFAULT_EXPORT_ERROR);
process.exit(1);
}
- await mod.default();
+ try {
+ await mod.default();
+ console.info(`${green('✔')} File run successfully.`);
+ } catch (e) {
+ if (e instanceof LibsqlError) {
+ throw new Error(EXEC_ERROR(e.message));
+ }
+ throw e;
+ }
}
diff --git a/packages/db/src/core/errors.ts b/packages/db/src/core/errors.ts
index 0724a74e9..198c86b78 100644
--- a/packages/db/src/core/errors.ts
+++ b/packages/db/src/core/errors.ts
@@ -41,11 +41,16 @@ export const SEED_ERROR = (error: string) => {
return `${red(`Error while seeding database:`)}\n\n${error}`;
};
+export const EXEC_ERROR = (error: string) => {
+ return `${red(`Error while executing file:`)}\n\n${error}`;
+};
+
export const SEED_DEFAULT_EXPORT_ERROR = (fileName: string) => {
- return (
- red('Error while seeding database:') +
- `\n\nMissing default function export in ${bold(fileName)}`
- );
+ return SEED_ERROR(`Missing default function export in ${bold(fileName)}`);
+};
+
+export const EXEC_DEFAULT_EXPORT_ERROR = (fileName: string) => {
+ return EXEC_ERROR(`Missing default function export in ${bold(fileName)}`);
};
export const REFERENCE_DNE_ERROR = (columnName: string) => {