Skip to content

Commit

Permalink
fix: restore cursor visibility in case of errors (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
yalhyane committed Mar 14, 2023
1 parent 1b01c2d commit 51a8bb0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
19 changes: 12 additions & 7 deletions src/commands/aicommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.');
}

Expand All @@ -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.');
Expand Down
19 changes: 11 additions & 8 deletions src/commands/prepare-commit-msg-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;

Expand Down

0 comments on commit 51a8bb0

Please sign in to comment.