feat: show error stack on unknown error (#124)

* feat: show error stack on unknown error

* improve message
This commit is contained in:
hiroki osame
2023-03-03 00:58:22 -05:00
committed by GitHub
parent 915a4ada60
commit 5fe127d377
8 changed files with 45 additions and 14 deletions

View File

@@ -12,6 +12,7 @@ import {
} from '../utils/git.js';
import { getConfig } from '../utils/config.js';
import { generateCommitMessage } from '../utils/openai.js';
import { KnownError, handleCliError } from '../utils/error.js';
export default async (
generate: number,
@@ -26,7 +27,7 @@ export default async (
const staged = await getStagedDiff();
if (!staged) {
throw new Error('No staged changes found. Make sure to stage your changes with `git add`.');
throw new KnownError('No staged changes found. Make sure to stage your changes with `git add`.');
}
detectingFiles.stop(`${getDetectedMessage(staged.files)}:\n${
@@ -36,7 +37,7 @@ export default async (
const config = await getConfig();
const OPENAI_KEY = process.env.OPENAI_KEY ?? process.env.OPENAI_API_KEY ?? config.OPENAI_KEY;
if (!OPENAI_KEY) {
throw new Error('Please set your OpenAI API key in ~/.aicommits');
throw new KnownError('Please set your OpenAI API key via `aicommits config set OPENAI_KEY=<your token>`');
}
const s = spinner();
@@ -78,5 +79,6 @@ export default async (
outro(`${green('✔')} Successfully committed!`);
})().catch((error) => {
outro(`${red('✖')} ${error.message}`);
handleCliError(error);
process.exit(1);
});