continue icon indicating copy to clipboard operation
continue copied to clipboard

Error: Execution of Slash Command without Additional Text in v0.9.65

Open LangLangBart opened this issue 1 year ago • 2 comments

Before submitting your bug report

Relevant environment info

- OS: macOS
- Continue: 0.9.65
- IDE: VSCode

Description

When executing a slashCommand without any other text, Continue throws an error starting from version v0.9.65 (2024-02-16T03:10:28.49Z).

This issue first appeared with commit f8e968c0 in the resolveParagraph function in the resolveInput.ts file due to the usage of the trimStart() method.

--- a/gui/src/components/mainInput/resolveInput.ts
+++ b/gui/src/components/mainInput/resolveInput.ts
@@ -148,25 +148,26 @@
 function resolveParagraph(p: JSONContent): [string, MentionAttrs[], string] {
   let text = "";
   const contextItems = [];
   let slashCommand = undefined;
   for (const child of p.content || []) {
     if (child.type === "text") {
-      text += child.text;
+      text += text === "" ? child.text.trimStart() : child.text;
     } else if (child.type === "mention") {

This leads to an issue in the resolveEditorContent function, as lastTextIndex becomes -1. This throws an error when parts[lastTextIndex].text is executed.

https://github.com/continuedev/continue/blob/2753ed4c2283f1a92be5ee97e4c02b010f96d825/gui/src/components/mainInput/resolveInput.ts#L128-L131

TypeError: Cannot read properties of undefined (reading 'text')

proposed solution/ workaround

Ensure lastTextIndex has found a match; if not, simply pass the slashCommand along.

--- a/gui/src/components/mainInput/resolveInput.ts
+++ b/gui/src/components/mainInput/resolveInput.ts
@@ -127,7 +127,12 @@ async function resolveEditorContent(
 
   if (slashCommand) {
     let lastTextIndex = findLastIndex(parts, (part) => part.type === "text");
-    parts[lastTextIndex].text = `${slashCommand} ${parts[lastTextIndex].text}`;
+    if (lastTextIndex !== -1) {
+      parts[lastTextIndex].text = `${slashCommand} ${parts[lastTextIndex].text}`;
+    }
+    else {
+      parts.push({ type: "text", text: slashCommand });
+    }
   }
 
   return [contextItems, parts];

To reproduce

  1. Enter a slash command in the continue GUI, without adding any text or context, for example, /edit.
  2. Press ⏎ Enter
  3. Notice the error message.

Log output

index.js:593 Continue: error streaming response:  TypeError: Cannot read properties of undefined (reading 'text')
    at resolveEditorContent (index.js:593:82)
    at rI (index.js:593:2015)
    at Object.current (index.js:1277:2346)
    at Enter (index.js:1191:1842)
    at index.js:812:5013
    at Plugin.<anonymous> (index.js:810:59037)
    at index.js:810:7375
    at EditorView.someProp (index.js:810:52817)
    at editHandlers.keydown (index.js:810:7346)
    at eI.dom.addEventListener.eI.input.eventHandlers.<computed> (index.js:810:5627)
workbench.desktop.main.js:769 Error streaming response: Cannot read properties of undefined (reading 'text')
onDidChangeNotification @ workbench.desktop.main.js:769
(anonymous) @ workbench.desktop.main.js:769
_deliver @ workbench.desktop.main.js:87
_deliverQueue @ workbench.desktop.main.js:87
fire @ workbench.desktop.main.js:87
addNotification @ workbench.desktop.main.js:769
notify @ workbench.desktop.main.js:1666
(anonymous) @ workbench.desktop.main.js:1560
_showMessage @ workbench.desktop.main.js:1560
$showMessage @ workbench.desktop.main.js:1560
_doInvokeHandler @ workbench.desktop.main.js:1567
_invokeHandler @ workbench.desktop.main.js:1567
_receiveRequest @ workbench.desktop.main.js:1567
_receiveOneMessage @ workbench.desktop.main.js:1567
(anonymous) @ workbench.desktop.main.js:1567
_deliver @ workbench.desktop.main.js:87
fire @ workbench.desktop.main.js:87
fire @ workbench.desktop.main.js:616
K.onmessage @ workbench.desktop.main.js:1663

LangLangBart avatar Feb 17 '24 09:02 LangLangBart

Thank you, fixing this today

sestinj avatar Feb 19 '24 18:02 sestinj

Kindly ping

eternalphane avatar Feb 23 '24 09:02 eternalphane

v0.9.73

Fixed with commit: 83e05352510c171f7f8b7ed6db0f055cbdb9b44a

LangLangBart avatar Feb 28 '24 05:02 LangLangBart