An RPC call failed with a signature that means the client transport doesn't match the
server (classic: http client → WebSocket server → Effect's "empty HTTP response" defect).
Remapped at the Hyperlink.client boundary so the failure is catchable by _tag
instead of looking like an opaque RpcClientDefect. Topology already designs this out on
the blessed path (Node.connect derives the transport); this is the legible backstop
when an escape-hatch protocol is still wrong.
export class class ProtocolMismatchclass ProtocolMismatch {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
resource: string;
method: string;
}
An RPC call failed with a signature that means the client transport doesn't match the
server (classic: http client → WebSocket server → Effect's "empty HTTP response" defect).
Remapped at the
Hyperlink.client
boundary so the failure is catchable by _tag
instead of looking like an opaque RpcClientDefect. Topology already designs this out on
the blessed path (
Node.connect
derives the transport); this is the legible backstop
when an escape-hatch protocol is still wrong.
ProtocolMismatch extends import DataData.const TaggedError: <"ProtocolMismatch">(tag: "ProtocolMismatch") => new <A>(args: VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => YieldableError & {
readonly _tag: "ProtocolMismatch";
} & Readonly<A>
Creates a tagged error class with a _tag discriminator.
When to use
Use when you need domain errors with discriminated-union handling.
Details
Like
Error
, but instances also carry a readonly _tag property,
enabling Effect.catchTag and Effect.catchTags for tag-based recovery.
The _tag is excluded from the constructor argument. Yielding an instance
inside Effect.gen fails the effect with this error.
Example (Recovering by tag)
import { Data, Effect } from "effect"
class NotFound extends Data.TaggedError("NotFound")<{
readonly resource: string
}> {}
class Forbidden extends Data.TaggedError("Forbidden")<{
readonly reason: string
}> {}
const program = Effect.gen(function*() {
return yield* new NotFound({ resource: "/users/42" })
})
const recovered = program.pipe(
Effect.catchTag("NotFound", (e) =>
Effect.succeed(`missing: ${e.resource}`))
)
TaggedError("ProtocolMismatch")<{
readonly resource: stringresource: string;
readonly method: stringmethod: string;
readonly cause: unknowncause: unknown;
}> {
override get ProtocolMismatch.message: stringmessage() {
return (
`Hyperlink "${this.resource: stringresource}" method "${this.method: stringmethod}" hit a transport/protocol mismatch ` +
`(often an http client dialing a WebSocket server). Use Node.connect / the node's declared ` +
`kind (protocolWebsocket / socketClient), not a guessed transport.`
);
}
}