refactor(sketch): tighten review feedback

- workspace-routing best-effort probe: catch ONLY SessionNotFound
  (was Effect.catch(() => undefined) which swallowed all E-channel
  errors, broader than the prior catchDefect-only behavior). Drop the
  now-redundant catchDefect since session.get fails typed instead of
  throwing.
- trace.ts: TODO(typed-errors) marker on the legacy Hono shim so it
  greps as a known retirement target.
- httpapi-parity.test.ts: drop stale FIXME comment above the now-
  passing reproducer.
This commit is contained in:
Kit Langton 2026-05-03 00:17:59 -04:00
commit 4837bb8904
3 changed files with 14 additions and 19 deletions

View file

@ -179,10 +179,12 @@ function routeHttpApiWorkspace<E>(
const sessionID = getWorkspaceRouteSessionID(requestURL(request)) const sessionID = getWorkspaceRouteSessionID(requestURL(request))
const session = sessionID const session = sessionID
? yield* Session.Service.use((svc) => svc.get(sessionID)).pipe( ? yield* Session.Service.use((svc) => svc.get(sessionID)).pipe(
// Sketch: also swallow the typed `SessionNotFound` so this routing // Best-effort routing probe: swallow only the typed SessionNotFound;
// probe stays best-effort (matches the previous defect-only catch). // any other error must propagate.
Effect.catch(() => Effect.succeed(undefined)), Effect.catchIf(
Effect.catchDefect(() => Effect.succeed(undefined)), (err): err is Session.SessionNotFound => err instanceof Session.SessionNotFound,
() => Effect.succeed(undefined),
),
) )
: undefined : undefined
const plan = yield* planRequest(request, session?.workspaceID) const plan = yield* planRequest(request, session?.workspaceID)

View file

@ -42,11 +42,10 @@ export function requestAttributes(c: RequestLike): Record<string, string> {
return attributes return attributes
} }
// Bridge typed service errors to the legacy Hono `NamedError` ErrorMiddleware. // TODO(typed-errors): bridge typed service errors to the legacy Hono
// The HttpApi adapter consumes typed errors directly via schema annotations, // `NamedError` ErrorMiddleware. HttpApi consumes typed errors directly via
// but Hono's ErrorMiddleware switches on `instanceof NamedError`. Until the // schema annotations, but Hono's ErrorMiddleware switches on
// legacy adapter is retired, catch the new typed errors here and rethrow the // `instanceof NamedError`. Delete this shim once the legacy adapter retires.
// equivalent NamedError so the existing 404 wiring keeps working.
const adaptTypedErrors = <A, E, R>( const adaptTypedErrors = <A, E, R>(
self: Effect.Effect<A, E, R>, self: Effect.Effect<A, E, R>,
): Effect.Effect<A, Exclude<E, Session.SessionNotFound>, R> => ): Effect.Effect<A, Exclude<E, Session.SessionNotFound>, R> =>

View file

@ -105,18 +105,12 @@ describe("404 mapping for missing session", () => {
}) })
// ────────────────────────────────────────────────────────────────────────────── // ──────────────────────────────────────────────────────────────────────────────
// Reproducer 3: 404 response body shape should match Hono's NamedError // Reproducer 3: 404 response body matches Hono's NamedError envelope
// envelope `{ name, data: { message } }`. HttpApi returns the typed-error // `{ name, data: { message } }`. `Session.get` now fails with a typed
// shape `{ _tag }` instead. SDK consumers reading `error.data.message` // `SessionNotFound` annotated `httpApiStatus: 404`. The endpoint declares the
// see undefined. // schema; HttpApi auto-routes status + body — no `mapNotFound` wrapper.
//
// FIXME: unskip when error JSON shape policy is decided + applied (separate PR).
// ────────────────────────────────────────────────────────────────────────────── // ──────────────────────────────────────────────────────────────────────────────
describe("Error JSON shape parity", () => { describe("Error JSON shape parity", () => {
// Sketch: validates the typed-error pattern end-to-end on `session.get`. The
// service now fails with a typed `SessionNotFound` error annotated
// `httpApiStatus: 404`. The endpoint declares the schema, and HttpApi auto-
// routes the status + body — no `mapNotFound` wrapper required.
test("HttpApi 404 body matches NamedError shape (sketch: session.get)", async () => { test("HttpApi 404 body matches NamedError shape (sketch: session.get)", async () => {
await using tmp = await tmpdir({ config: { formatter: false, lsp: false } }) await using tmp = await tmpdir({ config: { formatter: false, lsp: false } })