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

  1. Run the OpenCode CLI directly with the same prompt and fix whatever error it prints (usually `opencode` then check auth/provider setup)
  2. Ensure a default model/provider is configured and authenticated in OpenCode
  3. Update OpenCode to a version whose event output matches the expected schema, or pin the last working one
  4. 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

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


AI-assisted analysis of abhigyanpatwari/GitNexus@52924ef12c (2026-08-20). Data as JSON: /api/errors/67b2ce324d770530. Report an issue: GitHub.