Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/opencode/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Effect, Layer, Record, Result, Schema, Context } from "effect"
import { zod } from "@/util/effect-zod"
import { Global } from "@opencode-ai/core/global"
import { AppFileSystem } from "@opencode-ai/core/filesystem"
import { Log } from "@/util"

export const OAUTH_DUMMY_KEY = "opencode-oauth-dummy-key"

Expand Down Expand Up @@ -47,6 +48,8 @@ export interface Interface {
readonly remove: (key: string) => Effect.Effect<void, AuthError>
}

const log = Log.create({ service: "auth" })

export class Service extends Context.Service<Service, Interface>()("@opencode/Auth") {}

export const layer = Layer.effect(
Expand All @@ -59,7 +62,9 @@ export const layer = Layer.effect(
if (process.env.OPENCODE_AUTH_CONTENT) {
try {
return JSON.parse(process.env.OPENCODE_AUTH_CONTENT)
} catch (err) {}
} catch (err) {
log.warn("failed to parse OPENCODE_AUTH_CONTENT", { error: err })
}
}

const data = (yield* fsys.readJson(file).pipe(Effect.orElseSucceed(() => ({})))) as Record<string, unknown>
Expand Down
4 changes: 3 additions & 1 deletion packages/opencode/src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,9 @@ export const layer = Layer.effect(
for (const dpid of pids) {
try {
process.kill(dpid, "SIGTERM")
} catch {}
} catch (e) {
log.debug("process.kill SIGTERM failed", { error: e, pid: dpid })
}
}
}
yield* Effect.tryPromise(() => client.close()).pipe(Effect.ignore)
Expand Down
7 changes: 6 additions & 1 deletion packages/opencode/src/provider/error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { APICallError } from "ai"
import { STATUS_CODES } from "http"
import { iife } from "@/util/iife"
import { Log } from "@/util"
import type { ProviderID } from "./schema"

const log = Log.create({ service: "provider.error" })

// Adapted from overflow detection patterns in:
// https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/utils/overflow.ts
const OVERFLOW_PATTERNS = [
Expand Down Expand Up @@ -68,7 +71,9 @@ function message(providerID: ProviderID, e: APICallError) {
if (errMsg && typeof errMsg === "string") {
return `${msg}: ${errMsg}`
}
} catch {}
} catch (e) {
log.debug("JSON.parse of responseBody failed", { error: e })
}

// If responseBody is HTML (e.g. from a gateway or proxy error page),
// provide a human-readable message instead of dumping raw markup
Expand Down
8 changes: 6 additions & 2 deletions packages/opencode/src/pty/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,15 @@ export const layer = Layer.effect(
function teardown(session: Active) {
try {
session.process.kill()
} catch {}
} catch (e) {
log.debug("process.kill failed", { error: e })
}
for (const [sub, ws] of session.subscribers.entries()) {
try {
if (sock(ws) === sub) ws.close()
} catch {}
} catch (e) {
log.debug("ws.close failed", { error: e })
}
}
session.subscribers.clear()
}
Expand Down
4 changes: 3 additions & 1 deletion packages/opencode/src/server/mdns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export function publish(port: number, domain?: string) {
if (bonjour) {
try {
bonjour.destroy()
} catch {}
} catch (err) {
log.warn("bonjour.destroy() failed", { error: err })
}
}
bonjour = undefined
currentPort = undefined
Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/src/session/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ const live: Layer.Layer<
metadata: typeof result === "object" ? result?.metadata : undefined,
title: typeof result === "object" ? result?.title : undefined,
}
} catch (e: any) {
return { result: "", error: e.message ?? String(e) }
} catch (e: unknown) {
return { result: "", error: e instanceof Error ? e.message : String(e) }
}
}

Expand Down
7 changes: 6 additions & 1 deletion packages/opencode/src/session/message-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { zod, ZodOverride } from "@/util/effect-zod"
import { NonNegativeInt, withStatics } from "@/util/schema"
import { namedSchemaError } from "@/util/named-schema-error"
import { EffectLogger } from "@/effect"
import { Log } from "@/util"

const log = Log.create({ service: "message-v2" })

/** Error shape thrown by Bun's fetch() when gzip/br decompression fails mid-stream */
interface FetchDecompressionError extends Error {
Expand Down Expand Up @@ -1188,7 +1191,9 @@ export function fromError(
},
).toObject()
}
} catch {}
} catch (e) {
log.debug("failed to parse stream error", { error: e })
}
return new NamedError.Unknown({ message: JSON.stringify(e) }, { cause: e }).toObject()
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ export const layer: Layer.Layer<Service, never, Bus.Service | Storage.Service> =
SyncEvent.remove(sessionID)
})
} catch (e) {
log.warn("session remove failed", { error: e })
log.error(e)
}
})
Expand Down
6 changes: 5 additions & 1 deletion packages/opencode/src/util/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { isRecord } from "./record"
import { Log } from "@/util"

const log = Log.create({ service: "util.error" })

export function errorFormat(error: unknown): string {
if (error instanceof Error) {
Expand All @@ -8,7 +11,8 @@ export function errorFormat(error: unknown): string {
if (typeof error === "object" && error !== null) {
try {
return JSON.stringify(error, null, 2)
} catch {
} catch (e) {
log.debug("JSON.stringify failed", { error: e })
return "Unexpected error (unserializable)"
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/opencode/src/util/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { dirname, join, relative, resolve as pathResolve, win32 } from "path"
import { Readable } from "stream"
import { pipeline } from "stream/promises"
import { Glob } from "@opencode-ai/core/util/glob"
import { Log } from "@/util"

const log = Log.create({ service: "filesystem" })

// Fast sync version for metadata checks
export async function exists(p: string): Promise<boolean> {
Expand All @@ -14,7 +17,8 @@ export async function exists(p: string): Promise<boolean> {
export async function isDir(p: string): Promise<boolean> {
try {
return statSync(p).isDirectory()
} catch {
} catch (e) {
log.debug("statSync failed", { error: e, path: p })
return false
}
}
Expand Down
Loading