abhigyanpatwari/GitNexus · error · Error
OpenCode CLI returned error event: ${message}
Error message
OpenCode CLI returned error event: ${message} What it means
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.
Source
Thrown at gitnexus/src/core/wiki/local-cli-client.ts:207
const textParts: string[] = [];
for (const line of lines) {
let event: OpenCodeEvent;
try {
event = JSON.parse(line) as OpenCodeEvent;
} catch {
continue;
}
if (event.type === 'error') {
const message =
event.error?.data?.message ||
event.error?.name ||
event.message ||
event.part?.text ||
line;
throw new Error(`OpenCode CLI returned error event: ${message}`);
}
if (event.type === 'text' && typeof event.part?.text === 'string') {
textParts.push(event.part.text);
}
}
const content = textParts.join('').trim();
if (!content) {
throw new Error('OpenCode CLI returned no text output');
}
return content;
}
function buildChildEnv(provider: LocalAgentProvider): NodeJS.ProcessEnv {
const env: NodeJS.ProcessEnv = {
...process.env,
CI: '1',View on GitHub (pinned to 52924ef12c)
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)
Example fix
# before gitnexus wiki --provider opencode # error event: provider not authenticated # after opencode # complete provider auth/model setup in TUI gitnexus wiki --provider opencode
Defensive patterns
Strategy: try-catch
Try / catch
try {
const content = await runOpenCode(prompt, config);
} catch (err) {
if (err instanceof Error && err.message.startsWith('OpenCode CLI returned error event:')) {
const detail = err.message.split('error event: ')[1] ?? '';
if (/auth|credential|api key/i.test(detail)) throw new Error('Re-authenticate opencode and retry');
if (/model/i.test(detail)) throw new Error('Fix the opencode model config and retry');
throw err;
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- --allow-insecure-connection / GITNEXUS_ALLOW_INSECURE_CONNEC
- Invalid LLM base URL: must be a well-formed http:// or https
- LLM base URL must use http:// or https:// (got ${parsed.prot
- Insecure http:// LLM base URLs are only allowed for localhos
- LLM endpoint circuit open: retry in ${Math.ceil(err.retryAft
AI-assisted analysis of abhigyanpatwari/GitNexus@52924ef12c (2026-08-20).
Data as JSON: /api/errors/67b2ce324d770530.
Report an issue: GitHub.