fix: restore cursor visibility in case of errors (#154)

This commit is contained in:
yalhyane
2023-03-14 13:42:34 +01:00
committed by GitHub
parent 1b01c2d95a
commit 51a8bb0653
2 changed files with 23 additions and 15 deletions

View File

@@ -27,6 +27,7 @@ export default async (
const staged = await getStagedDiff();
if (!staged) {
detectingFiles.stop('Detecting staged files');
throw new KnownError('No staged changes found. Make sure to stage your changes with `git add`.');
}
@@ -41,13 +42,17 @@ export default async (
const s = spinner();
s.start('The AI is analyzing your changes');
const messages = await generateCommitMessage(
config.OPENAI_KEY,
config.locale,
staged.diff,
config.generate,
);
s.stop('Changes analyzed');
let messages: string[];
try {
messages = await generateCommitMessage(
config.OPENAI_KEY,
config.locale,
staged.diff,
config.generate,
);
} finally {
s.stop('Changes analyzed');
}
if (messages.length === 0) {
throw new KnownError('No commit messages were generated. Try again.');

View File

@@ -34,14 +34,17 @@ export default () => (async () => {
const s = spinner();
s.start('The AI is analyzing your changes');
const messages = await generateCommitMessage(
config.OPENAI_KEY,
config.locale,
staged!.diff,
config.generate,
);
s.stop('Changes analyzed');
let messages: string[];
try {
messages = await generateCommitMessage(
config.OPENAI_KEY,
config.locale,
staged!.diff,
config.generate,
);
} finally {
s.stop('Changes analyzed');
}
const hasMultipleMessages = messages.length > 1;
let instructions = `# 🤖 AI generated commit${hasMultipleMessages ? 's' : ''}\n`;