Skip to content

Do error types created by extending Data.TaggedError form a discriminate union in the error channel? #1497

Description

@shibisuriya

What is the type of issue?

Documentation is confusing

What is the issue?

import { Data, Effect } from 'effect'

class NotFound extends Data.TaggedError('NotFound') {}

class NotFound1 extends Data.TaggedError('NotFound') {}

function getUser(id: number) {
    return Effect.gen(function* () {
        if (id === 1) {
            return 'Shibi'
        } else if (id === 2) {
            return yield* new NotFound1()
        } else if (id === 3) {
            return yield* new NotFound()
        }
    })
}

const program = getUser(1).pipe(
    Effect.catchTag('NotFound', (err) => {
        return Effect.succeed(err)
    })
)

Technically this shouldn't compile... Even if it compiles the program should crash with a defect because the discriminator ('_tag') is same for NotFound & NotFound1 (these two are used in the same error channel, if they were used in different effect's error channel then it is not an issue).

Either the the points mentioned above are truth or the docs needs rewriting to avoid confusion...

Where did you find it?

https://www.effect.website/docs/v4/error-management/yieldable-errors#datataggederror

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions