mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
feat(db): execute
command logs (#10439)
* feat: db execute success and error logs * chore: changeset
This commit is contained in:
parent
f8e0ad3c52
commit
0989cd3284
3 changed files with 28 additions and 7 deletions
5
.changeset/hip-mugs-know.md
Normal file
5
.changeset/hip-mugs-know.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/db": patch
|
||||
---
|
||||
|
||||
Add success and error logs to `astro db execute` command
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue