Skip to content

Commit 60ec4c3

Browse files
committed
fix(protocol,server,client): use named error classes with name field for codegen compatibility
1 parent 37d06c5 commit 60ec4c3

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎packages/protocol/src/groups/schedule.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/un
44
import { LocationQuery, locationQueryOpenApi } from "./location"
55

66
export class ScheduleValidationError extends Schema.ErrorClass<ScheduleValidationError>("ScheduleValidationError")(
7-
{ message: Schema.String },
7+
{
8+
name: Schema.Literal("ScheduleValidationError"),
9+
message: Schema.String,
10+
},
811
{ httpApiStatus: 400 },
912
) {}
1013

‎packages/protocol/src/groups/system.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { Schema } from "effect"
2-
import { HttpApiEndpoint, HttpApiError, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
2+
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
3+
4+
export class SystemUpdateError extends Schema.ErrorClass<SystemUpdateError>("SystemUpdateError")(
5+
{
6+
name: Schema.Literal("SystemUpdateError"),
7+
message: Schema.String,
8+
},
9+
{ httpApiStatus: 400 },
10+
) {}
311

412
export const SystemGroup = HttpApiGroup.make("server.system").add(
513
HttpApiEndpoint.post("system.update", "/api/system/update", {
@@ -11,7 +19,7 @@ export const SystemGroup = HttpApiGroup.make("server.system").add(
1119
message: Schema.String,
1220
currentVersion: Schema.optional(Schema.String),
1321
}),
14-
error: [HttpApiError.BadRequest],
22+
error: SystemUpdateError,
1523
}).annotateMerge(
1624
OpenApi.annotations({
1725
identifier: "v2.system.update",

‎packages/server/src/handlers/schedule.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ export const ScheduleHandler = HttpApiBuilder.group(Api, "server.schedule", (han
2424
workspace: ctx.payload.workspace,
2525
enabled: ctx.payload.enabled,
2626
})
27-
.pipe(Effect.catch((error) => new ScheduleValidationError({ message: error.message })))
27+
.pipe(Effect.catch((error) => new ScheduleValidationError({ name: "ScheduleValidationError", message: error.message })))
2828
}),
2929
)
3030
.handle(
3131
"schedule.run",
3232
Effect.fn(function* (ctx) {
3333
return yield* ScheduleRunner.runOne(ctx.params.scheduleID).pipe(
34-
Effect.catch((error) => new ScheduleValidationError({ message: `Schedule "${error.id}" not found` })),
34+
Effect.catch((error) => new ScheduleValidationError({ name: "ScheduleValidationError", message: `Schedule "${error.id}" not found` })),
3535
)
3636
}),
3737
)

‎packages/server/src/handlers/system.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { InstallationVersion } from "@opencode-ai/core/installation/version"
22
import { Effect } from "effect"
3-
import { HttpApiBuilder, HttpApiError } from "effect/unstable/httpapi"
3+
import { HttpApiBuilder } from "effect/unstable/httpapi"
44
import { Api } from "../api"
5+
import { SystemUpdateError } from "@opencode-ai/protocol/groups/system"
56

67
export const SystemHandler = HttpApiBuilder.group(Api, "server.system", (handlers) =>
78
handlers.handle(
89
"system.update",
910
Effect.fn(function* (ctx) {
1011
if (!ctx.payload.confirm) {
11-
return yield* new HttpApiError.BadRequest()
12+
return yield* new SystemUpdateError({ name: "SystemUpdateError", message: "Confirmation required" })
1213
}
1314

1415
yield* Effect.logInfo(`[System] Remote update triggered by authenticated client`)

0 commit comments

Comments
 (0)