Skip to content
Discussion options

You must be logged in to vote

The issue is Schema.instanceOf(UnluckError)instanceOf checks the class instance but doesn't know how to encode it as a plain object. It passes the class instance through as-is, which serializes to {} (class instances have non-enumerable prototype methods).

Fix: use Schema.TaggedError instead of Data.TaggedError + instanceOf:

import { Console, Effect, pipe, Schema } from "effect";

// Define the error WITH a schema (not just Data.TaggedError)
class UnluckError extends Schema.TaggedError<UnluckError>()("UnluckError", {
  rolled: Schema.Number,
}) {}

Effect.runPromise(
  pipe(
    Effect.sync(() => Math.random()),
    Effect.flatMap((rolled) =>
      rolled > 0.5
        ? Effect.succeed(1…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@piscopancer
Comment options

Answer selected by piscopancer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants