different-ai/openwork · error

Unknown error

Error message

Unknown error

What it means

assertNoClientError normalizes an error attached to an opencode session result (Error instance, plain string, or arbitrary value stringified via JSON.stringify) into a thrown Error. When the error value serializes to an empty string, the fallback message "Unknown error" is used. Called by compactSession and shellInSession.

Source

Thrown at apps/app/src/app/lib/opencode-session.ts:262

  } catch {
    return [];
  }
}

// ---------------------------------------------------------------------------
// Internal
// ---------------------------------------------------------------------------

function assertNoClientError(result: unknown): void {
  const maybe = result as { error?: unknown } | null | undefined;
  if (!maybe || maybe.error === undefined) return;
  const message =
    maybe.error instanceof Error
      ? maybe.error.message
      : typeof maybe.error === "string"
        ? maybe.error
        : JSON.stringify(maybe.error);
  throw new Error(message || "Unknown error");
}

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Log the full result object before this assertion to see what the error actually contains.
  2. Check the opencode server logs for the request that failed; the message was likely lost client-side.
  3. Inspect opencode SDK version for changed error payload shape and update the extraction to read the right field.

Example fix

// before: stringify loses detail
: JSON.stringify(maybe.error);
// after: include raw payload for diagnosis
throw new Error(message || `Unknown error: ${JSON.stringify(maybe.error ?? null)}`);
Defensive patterns

Strategy: try-catch

Validate before calling

if (result && typeof result === "object" && "error" in result && result.error != null) {
  console.debug("session error payload:", result.error); // inspect before assert throws
}

Type guard

function hasMeaningfulError(e: unknown): e is { error: string | Error } {
  if (e == null) return false;
  if (e instanceof Error) return e.message.length > 0;
  if (typeof e === "string") return e.length > 0;
  return JSON.stringify(e) !== "{}";
}

Try / catch

try {
  await compactSession(sessionId);
} catch (err) {
  if (err instanceof Error && err.message === "Unknown error") {
    // message was lost; re-read session state / check server logs
    await refreshSessionFromServer(sessionId);
  } else throw err;
}

Prevention

When it happens

Trigger: An opencode client call (compact, shell) returns a result object whose `error` field is set but produces an empty message — e.g. `error: ""`, `error: null` with truthiness already checked, or an object that stringifies to empty.

Common situations: Server-side failure with no message body, aborted request where the SDK sets a bare error flag, or schema drift where the error payload moved to a different field.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/781734d0c37cef10. Report an issue: GitHub.