Skip to content

Commit 51d15bf

Browse files
committed
Improve error handling
1 parent 3994d00 commit 51d15bf

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

plugin/src/de/hetzge/eclipse/aicoder/inline/InlineCompletionController.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package de.hetzge.eclipse.aicoder.inline;
22

3-
import java.awt.datatransfer.UnsupportedFlavorException;
4-
import java.io.IOException;
53
import java.util.HashSet;
64
import java.util.List;
75
import java.util.Map;
@@ -66,6 +64,7 @@
6664
// TODO spacing bug while completion is open
6765
// TODO overlay moves while scrolling bug
6866
// TODO regenerate button in inline suggestion
67+
// TODO last input tokens status bar information (to keep an eye on token usage), use colors to indicate if it is too much
6968

7069
public final class InlineCompletionController {
7170

@@ -185,6 +184,7 @@ public void trigger(String instruction) {
185184
final AiCoderHistoryEntry historyEntry = new AiCoderHistoryEntry(mode, filePath, this.textViewer.getDocument().get());
186185
this.job = Job.create("AI completion", monitor -> {
187186
String prompt = "";
187+
LlmResponse llmResponse = null;
188188
try {
189189
updateHistoryEntry(historyEntry);
190190
final int modelOffset = EclipseUtils.getCurrentOffsetInDocument(InlineCompletionController.this.textEditor);
@@ -197,7 +197,6 @@ public void trigger(String instruction) {
197197
final String prefix = contextParts[0];
198198
final String suffix = contextParts.length > 1 ? contextParts[1] : "";
199199
final String selectionText = EclipseUtils.getSelectionText(this.textViewer);
200-
LlmResponse llmResponse = null;
201200
if (mode == CompletionMode.EDIT || mode == CompletionMode.GENERATE || mode == CompletionMode.QUICK_FIX) {
202201
final String fileType = EclipseUtils.getFileExtension(this.textEditor.getEditorInput());
203202
final String systemPrompt = hasSelection
@@ -280,19 +279,19 @@ public void trigger(String instruction) {
280279
historyEntry.setInput(prompt);
281280
historyEntry.setOutput(content);
282281
updateHistoryEntry(historyEntry);
283-
} catch (final IOException | BadLocationException | UnsupportedFlavorException exception) {
282+
} catch (final Exception exception) {
284283
AiCoderActivator.log().error("AI Coder completion failed", exception);
285284
final long duration = System.currentTimeMillis() - startTime;
286285
final String stacktrace = Utils.getStacktraceString(exception);
287286
historyEntry.setStatus(HistoryStatus.ERROR);
288287
historyEntry.setDurationMs(duration);
289288
historyEntry.setLlmDurationMs(0);
290-
historyEntry.setPlainLlmResponse(stacktrace);
289+
historyEntry.setPlainLlmResponse(llmResponse != null ? llmResponse.getPlainResponse() : "");
291290
historyEntry.setModelLabel(null);
292291
historyEntry.setInputTokenCount(0);
293292
historyEntry.setOutputTokenCount(0);
294293
historyEntry.setInput(prompt);
295-
historyEntry.setOutput(stacktrace);
294+
historyEntry.setOutput((llmResponse != null ? llmResponse.getContent() : "") + stacktrace);
296295
updateHistoryEntry(historyEntry);
297296
}
298297
});

0 commit comments

Comments
 (0)