fix(cli/run): properly serialize error objects to prevent [object Object] output

- Add serializeError utility to handle Error instances, plain objects, and nested message paths
- Fix handleSessionError to use serializeError instead of naive String() conversion
- Fix runner.ts catch block to use serializeError for detailed error messages
- Add session.error case to logEventVerbose for better error visibility
- Add comprehensive tests for serializeError function

Fixes error logging in sisyphus-agent workflow where errors were displayed as '[object Object]'
This commit is contained in:
YeonGyu-Kim
2026-01-12 14:49:07 +09:00
parent 965bb2dd10
commit f83b22c4de
3 changed files with 113 additions and 6 deletions
+58 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from "bun:test"
import { createEventState, type EventState } from "./events"
import { createEventState, serializeError, type EventState } from "./events"
import type { RunContext, EventPayload } from "./types"
const createMockContext = (sessionID: string = "test-session"): RunContext => ({
@@ -15,6 +15,63 @@ async function* toAsyncIterable<T>(items: T[]): AsyncIterable<T> {
}
}
describe("serializeError", () => {
it("returns 'Unknown error' for null/undefined", () => {
// #given / #when / #then
expect(serializeError(null)).toBe("Unknown error")
expect(serializeError(undefined)).toBe("Unknown error")
})
it("returns message from Error instance", () => {
// #given
const error = new Error("Something went wrong")
// #when / #then
expect(serializeError(error)).toBe("Something went wrong")
})
it("returns string as-is", () => {
// #given / #when / #then
expect(serializeError("Direct error message")).toBe("Direct error message")
})
it("extracts message from plain object", () => {
// #given
const errorObj = { message: "Object error message", code: "ERR_001" }
// #when / #then
expect(serializeError(errorObj)).toBe("Object error message")
})
it("extracts message from nested error object", () => {
// #given
const errorObj = { error: { message: "Nested error message" } }
// #when / #then
expect(serializeError(errorObj)).toBe("Nested error message")
})
it("extracts message from data.message path", () => {
// #given
const errorObj = { data: { message: "Data error message" } }
// #when / #then
expect(serializeError(errorObj)).toBe("Data error message")
})
it("JSON stringifies object without message property", () => {
// #given
const errorObj = { code: "ERR_001", status: 500 }
// #when
const result = serializeError(errorObj)
// #then
expect(result).toContain("ERR_001")
expect(result).toContain("500")
})
})
describe("createEventState", () => {
it("creates initial state with correct defaults", () => {
// #given / #when