mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(core): preserve job failure details (#49226)
This commit is contained in:
committed by
GitHub
Unverified
parent
70fe186df4
commit
01443d5e00
@@ -142,9 +142,14 @@ function snapshot(job: Active): Info {
|
||||
}
|
||||
}
|
||||
|
||||
function errorText(error: unknown) {
|
||||
if (error instanceof Error) return error.message
|
||||
return String(error)
|
||||
function errorText(cause: Cause.Cause<unknown>) {
|
||||
const render = (error: Error): string => {
|
||||
const message = error.message || error.name || "Unknown error"
|
||||
if (!(error.cause instanceof Error)) return message
|
||||
const detail = render(error.cause)
|
||||
return detail === message || detail.startsWith(`${message}\n`) ? detail : `${message}\nCaused by: ${detail}`
|
||||
}
|
||||
return Cause.prettyErrors(cause).map(render).join("\n") || "Unknown error"
|
||||
}
|
||||
|
||||
function incrementSession(input: Map<SessionSchema.ID, number>, sessionID: SessionSchema.ID) {
|
||||
@@ -205,7 +210,7 @@ export const make = Effect.gen(function* () {
|
||||
status,
|
||||
completed_at,
|
||||
...(Exit.isSuccess(exit) ? { output: exit.value } : {}),
|
||||
...(Exit.isFailure(exit) ? { error: errorText(Cause.squash(exit.cause)) } : {}),
|
||||
...(Exit.isFailure(exit) ? { error: errorText(exit.cause) } : {}),
|
||||
},
|
||||
}
|
||||
if (status !== "cancelled") yield* persistBackground(next)
|
||||
|
||||
@@ -2,8 +2,9 @@ import { describe, expect } from "bun:test"
|
||||
import { Job } from "@opencode/core/job"
|
||||
import { KV } from "@opencode/core/kv"
|
||||
import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
|
||||
import { Integration } from "@opencode/core/integration"
|
||||
import { LayerNode } from "@opencode/util/effect/layer-node"
|
||||
import { Deferred, Effect, Exit, Fiber, Scope } from "effect"
|
||||
import { Cause, Deferred, Effect, Exit, Fiber, Scope } from "effect"
|
||||
import { SessionSchema } from "@opencode/core/session/schema"
|
||||
import { testEffect } from "./lib/effect"
|
||||
|
||||
@@ -64,6 +65,30 @@ describe("Job", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("preserves authorization and complete failure details without stacks", () =>
|
||||
Effect.gen(function* () {
|
||||
const jobs = yield* Job.Service
|
||||
const job = yield* jobs.start({
|
||||
type: "test",
|
||||
run: Effect.failCause(
|
||||
Cause.combine(
|
||||
Cause.fail(
|
||||
new Integration.AuthorizationError({
|
||||
cause: new Error("authorization failed", { cause: new Error("token expired") }),
|
||||
}),
|
||||
),
|
||||
Cause.die({ code: "cleanup_failed" }),
|
||||
),
|
||||
),
|
||||
})
|
||||
|
||||
expect((yield* jobs.wait({ id: job.id })).info).toMatchObject({
|
||||
status: "error",
|
||||
error: 'authorization failed\nCaused by: token expired\n{"code":"cleanup_failed"}',
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
it.live("reuses running work when started again with the same ID", () =>
|
||||
Effect.gen(function* () {
|
||||
const jobs = yield* Job.Service
|
||||
|
||||
Reference in New Issue
Block a user