{"record":{"id":"67b2ce324d770530","repo":"abhigyanpatwari/GitNexus","slug":"opencode-cli-returned-error-event-message","errorCode":null,"errorMessage":"OpenCode CLI returned error event: ${message}","messagePattern":"OpenCode CLI returned error event: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/wiki/local-cli-client.ts","lineNumber":207,"sourceCode":"\n  const textParts: string[] = [];\n\n  for (const line of lines) {\n    let event: OpenCodeEvent;\n    try {\n      event = JSON.parse(line) as OpenCodeEvent;\n    } catch {\n      continue;\n    }\n\n    if (event.type === 'error') {\n      const message =\n        event.error?.data?.message ||\n        event.error?.name ||\n        event.message ||\n        event.part?.text ||\n        line;\n      throw new Error(`OpenCode CLI returned error event: ${message}`);\n    }\n\n    if (event.type === 'text' && typeof event.part?.text === 'string') {\n      textParts.push(event.part.text);\n    }\n  }\n\n  const content = textParts.join('').trim();\n  if (!content) {\n    throw new Error('OpenCode CLI returned no text output');\n  }\n  return content;\n}\n\nfunction buildChildEnv(provider: LocalAgentProvider): NodeJS.ProcessEnv {\n  const env: NodeJS.ProcessEnv = {\n    ...process.env,\n    CI: '1',","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/52924ef12c2290ceee4612526a828ec4cdf2047f/gitnexus/src/core/wiki/local-cli-client.ts#L189-L225","documentation":"For `--provider opencode`, gitnexus spawns the OpenCode CLI in event-stream mode and parses each NDJSON line as an OpenCodeEvent. Any event with type === 'error' aborts parsing and is rethrown with the most specific message available (error.data.message, error.name, top-level message, part.text, or the raw line). It surfaces whatever failure the OpenCode CLI reported — auth, model, or runtime errors.","triggerScenarios":"Running `gitnexus wiki --provider opencode` when the opencode CLI emits an error event: not authenticated, configured model unavailable, provider credentials missing, or an internal CLI error; the raw JSON line is shown only when the event carries none of the standard message fields.","commonSituations":"OpenCode installed but never logged in / no provider configured; model id in opencode config removed or renamed; opencode config changes after upgrade; transient provider auth expiry.","solutions":["Run the OpenCode CLI directly with the same prompt and fix whatever error it prints (usually `opencode` then check auth/provider setup)","Ensure a default model/provider is configured and authenticated in OpenCode","Update OpenCode to a version whose event output matches the expected schema, or pin the last working one","If the raw JSON line is shown, decode it for the underlying provider error code and address that (key, quota, model name)"],"exampleFix":"# before\ngitnexus wiki --provider opencode   # error event: provider not authenticated\n\n# after\nopencode   # complete provider auth/model setup in TUI\ngitnexus wiki --provider opencode","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const content = await runOpenCode(prompt, config);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('OpenCode CLI returned error event:')) {\n    const detail = err.message.split('error event: ')[1] ?? '';\n    if (/auth|credential|api key/i.test(detail)) throw new Error('Re-authenticate opencode and retry');\n    if (/model/i.test(detail)) throw new Error('Fix the opencode model config and retry');\n    throw err;\n  }\n}","preventionTips":["Run `opencode` interactively once and send a test prompt before using --provider opencode","Keep opencode provider/model config in version control so CI matches local","Log the raw error-event JSON when it appears — it carries the underlying provider error"],"tags":["llm","opencode","cli-error","event-stream","gitnexus"],"backgroundTag":"cli-runtime-error","analyzedSha":"52924ef12c2290ceee4612526a828ec4cdf2047f","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}