{"record":{"id":"ce1441dd66ba75a2","repo":"different-ai/openwork","slug":"unknown-error-ce1441","errorCode":null,"errorMessage":"Unknown error","messagePattern":"Unknown error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/app/src/app/lib/opencode.ts","lineNumber":269,"sourceCode":"        ...init,\n        headers,\n      },\n      timeoutMs,\n    );\n  };\n};\n\nexport function unwrap<T>(result: FieldsResult<T>): NonNullable<T> {\n  if (result.data !== undefined) {\n    return result.data as NonNullable<T>;\n  }\n  const message =\n    result.error instanceof Error\n      ? result.error.message\n      : typeof result.error === \"string\"\n        ? result.error\n        : JSON.stringify(result.error);\n  throw new Error(message || \"Unknown error\");\n}\n\nexport function createClient(baseUrl: string, directory?: string, auth?: OpencodeAuth) {\n  const headers: Record<string, string> = {};\n  if (!isDesktopRuntime()) {\n    const authHeader = resolveAuthHeader(auth);\n    if (authHeader) {\n      headers.Authorization = authHeader;\n    }\n  }\n\n  const fetchImpl = isDesktopRuntime()\n    ? createDesktopFetch(auth)\n    : (input: RequestInfo | URL, init?: RequestInit) => {\n        const timeoutMs = requestIsStreaming(input, init) ? 0 : DEFAULT_OPENCODE_REQUEST_TIMEOUT_MS;\n        return fetchWithTimeout(globalThis.fetch, input, init, timeoutMs);\n      };\n  const client = createOpencodeClient({","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/app/lib/opencode.ts#L251-L287","documentation":"unwrap converts an error carried on an opencode client result (Error, string, or any JSON value) into a thrown Error, falling back to \"Unknown error\" when the message is empty. It backs unwrapSessionResult, aborted, revertSession, forkSession, unrevertSession and setSessionArchived — any of these calls can surface it.","triggerScenarios":"An opencode client session operation returns `{ error: ... }` whose normalized message is empty: empty-string error, object that stringifies to empty, or an error field set without detail by the server/SDK.","commonSituations":"Session already deleted when calling revert/fork, server returning bare `{error:true}`-style bodies, SDK version mismatch between client expectations and server responses.","solutions":["Capture the raw result object at the call site to recover the real failure cause.","Check opencode server logs for the failing session operation (session id, route, status).","Align the opencode client SDK and server versions so error payloads match the expected shape."],"exampleFix":"// before\nthrow new Error(message || \"Unknown error\");\n// after: preserve the raw payload\nthrow new Error(message || `Unknown error: ${JSON.stringify(result.error ?? null)}`);","handlingStrategy":"try-catch","validationCode":"if (result && typeof result === \"object\" && \"error\" in result) {\n  console.debug(\"unwrap candidate error:\", result.error); // preserve payload before it is normalized away\n}","typeGuard":null,"tryCatchPattern":"try {\n  await forkSession(sessionId);\n} catch (err) {\n  if (err instanceof Error && err.message === \"Unknown error\") {\n    // detail lost in unwrap; verify session existence server-side\n    const s = await getClient().session.get(sessionId);\n    if (!s) throw new Error(`Session ${sessionId} not found (original error was empty).`);\n    throw err;\n  }\n  throw err;\n}","preventionTips":["Validate the session exists (get/archived state) before revert/fork/unrevert calls.","Align opencode client and server versions.","Attach the raw error payload to logs when unwrap falls back to \"Unknown error\"."],"tags":["opencode","session","error-handling"],"backgroundTag":"unknown-error-fallback","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}