Skip to content

Commit eb56592

Browse files
committed
Fixes stash generation error handling
1 parent 1542284 commit eb56592

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/ai/anthropicProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class AnthropicProvider extends OpenAICompatibleProvider<typeof provider.
128128
}
129129
if (rsp.status === 429) {
130130
throw new Error(
131-
`(${this.name}:${rsp.status}) Too many requests (rate limit exceeded) or your API key is associated with an expired trial`,
131+
`(${this.name}) ${rsp.status}: Too many requests (rate limit exceeded) or your API key is associated with an expired trial`,
132132
);
133133
}
134134

@@ -148,7 +148,7 @@ export class AnthropicProvider extends OpenAICompatibleProvider<typeof provider.
148148
continue;
149149
}
150150

151-
throw new Error(`(${this.name}:${rsp.status}) ${json?.error?.message || rsp.statusText})`);
151+
throw new Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText})`);
152152
}
153153

154154
const data: AnthropicMessageResponse = await rsp.json();

src/ai/openAICompatibleProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
272272
}
273273
if (rsp.status === 429) {
274274
throw new Error(
275-
`(${this.name}:${rsp.status}) Too many requests (rate limit exceeded) or your account is out of funds`,
275+
`(${this.name}) ${rsp.status}: Too many requests (rate limit exceeded) or your account is out of funds`,
276276
);
277277
}
278278

@@ -285,7 +285,7 @@ export abstract class OpenAICompatibleProvider<T extends AIProviders> implements
285285
return { retry: true, maxCodeCharacters: maxCodeCharacters - 500 };
286286
}
287287

288-
throw new Error(`(${this.name}:${rsp.status}) ${json?.error?.message || rsp.statusText}`);
288+
throw new Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`);
289289
}
290290

291291
protected async fetchCore(

src/commands/git/stash.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ export class StashGitCommand extends QuickCommand<State> {
637637
value: state.message,
638638
prompt: 'Enter stash message',
639639
buttons: [QuickInputButtons.Back, generateMessageButton],
640+
// Needed to clear any validation errors because of AI generation
641+
validate: (_value: string | undefined): [boolean, string | undefined] => [true, undefined],
640642
onDidClickButton: async (input, button) => {
641643
if (button === generateMessageButton) {
642644
using resume = step.freeze?.();
@@ -649,6 +651,7 @@ export class StashGitCommand extends QuickCommand<State> {
649651
);
650652
if (!diff?.contents) {
651653
void window.showInformationMessage('No changes to generate a stash message from.');
654+
return;
652655
}
653656

654657
const generating = defer<AIModel>();
@@ -668,7 +671,7 @@ export class StashGitCommand extends QuickCommand<State> {
668671

669672
const result = await (
670673
await this.container.ai
671-
)?.generateStashMessage(diff!.contents, { source: 'quick-wizard' }, { generating: generating });
674+
)?.generateStashMessage(diff.contents, { source: 'quick-wizard' }, { generating: generating });
672675

673676
input.validationMessage = undefined;
674677

@@ -679,11 +682,11 @@ export class StashGitCommand extends QuickCommand<State> {
679682
}
680683
} catch (ex) {
681684
Logger.error(ex, scope, 'generateStashMessage');
682-
if (ex instanceof Error && ex.message.startsWith('No changes')) {
683-
void window.showInformationMessage('No changes to generate a stash message from.');
684-
} else {
685-
void showGenericErrorMessage(ex.message);
686-
}
685+
686+
input.validationMessage = {
687+
severity: InputBoxValidationSeverity.Error,
688+
message: ex.message,
689+
};
687690
}
688691
}
689692
},

0 commit comments

Comments
 (0)