{"record":{"id":"460b47adeb0f037f","repo":"chatboxai/chatbox","slug":"unterminated-quoted-argument","errorCode":null,"errorMessage":"Unterminated quoted argument.","messagePattern":"Unterminated quoted argument\\.","errorType":"validation","errorClass":"ChatboxCliUsageError","httpStatus":null,"severity":"warning","filePath":"src/renderer/packages/chatbox-cli/parser.ts","lineNumber":49,"sourceCode":"      continue\n    }\n    if (char === \"'\" && quote !== 'double') {\n      quote = quote === 'single' ? null : 'single'\n      continue\n    }\n    if (char === '\"' && quote !== 'single') {\n      quote = quote === 'double' ? null : 'double'\n      continue\n    }\n    if (/\\s/.test(char) && quote === null) {\n      pushCurrent()\n      continue\n    }\n    current += char\n  }\n\n  if (escaping) current += '\\\\'\n  if (quote) throw new ChatboxCliUsageError('Unterminated quoted argument.')\n  pushCurrent()\n  return tokens\n}\n\nexport function parseChatboxCliInput(input: ChatboxCliInput): ParsedChatboxCommand {\n  const argv = input.argv\n    ? [...input.argv]\n    : typeof input.command === 'string'\n      ? tokenizeVirtualCommand(input.command)\n      : []\n  if (argv[0]?.toLowerCase() === 'chatbox' || argv[0]?.toLowerCase() === 'chatbox_cli') {\n    argv.shift()\n  }\n  return {\n    argv,\n    displayCommand: `chatbox${argv.length ? ` ${argv.join(' ')}` : ''}`,\n  }\n}","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/renderer/packages/chatbox-cli/parser.ts#L31-L67","documentation":"ChatboxCliUsageError thrown by tokenizeVirtualCommand after scanning the whole command string when the quote state is still non-null. It means an opening single or double quote was never closed; the tokenizer refuses to emit a partial token and the parsed command fails before dispatch.","triggerScenarios":"A command string like chatbox chats search \"hello (missing closing quote), an unbalanced apostrophe inside a double-quoted phrase mishandled by the caller, or a copy/paste that dropped the closing quote.","commonSituations":"An LLM generating a command string without matching quotes, a UI concatenating user input without escaping, or a localized string containing a stray quote.","solutions":["Prefer passing structured argv directly (executeChatboxCliCommand accepts { argv }) instead of a command string, eliminating tokenization.","If you must pass a command string, ensure every opening quote has a matching close and escape inner quotes.","Validate balanced quotes in the caller before sending and prompt the user to fix the input."],"exampleFix":"// before: command string with an unbalanced quote\nawait executeChatboxCliCommand({ command: 'chats search \"hello world' }, ctx)\n\n// after: pass structured argv to skip tokenization entirely\nawait executeChatboxCliCommand({ argv: ['chats', 'search', 'hello world'] }, ctx)","handlingStrategy":"validation","validationCode":"// Prefer structured argv to skip tokenization entirely.\nawait executeChatboxCliCommand({ argv: ['chats', 'search', rawQuery] }, ctx)\n\n// If you must pass a command string, validate balanced quotes first:\nfunction hasBalancedQuotes(command: string): boolean {\n  let quote: '\\'' | '\"' | null = null\n  let escaping = false\n  for (const ch of command) {\n    if (escaping) { escaping = false; continue }\n    if (ch === '\\\\' && quote !== '\\'') { escaping = true; continue }\n    if (ch === '\\'' && quote !== '\"') { quote = quote === '\\'' ? null : '\\''; continue }\n    if (ch === '\"' && quote !== '\\'') { quote = quote === '\"' ? null : '\"'; continue }\n  }\n  return quote === null\n}\nif (!hasBalancedQuotes(command)) {\n  return { error: 'Command has an unterminated quote', kind: 'usage' }\n}","typeGuard":null,"tryCatchPattern":"const parsed = parseChatboxCliInput({ command })\n// parseChatboxCliInput throws ChatboxCliUsageError on unbalanced quotes;\n// wrap callers and surface kind:'usage' to the user.\ntry {\n  await executeChatboxCliCommand({ command }, ctx)\n} catch (error) {\n  if (error instanceof ChatboxCliUsageError) {\n    // prompt the user to fix the unbalanced quote\n  } else throw error\n}","preventionTips":["Pass structured argv ({ argv: [...] }) instead of a command string to avoid tokenization entirely.","When building a command string, escape inner quotes and ensure every quote is closed.","Validate balanced quotes in the caller before sending."],"tags":["chatbox-cli","usage","parser","validation","escaping"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}