Skip to content

Why not refuse to start the program if two (or more) tagged errors used in an effect have the same _tag? #10843

Open

Description

@shibisuriya

What is the problem this feature would solve?

Screenshot 2026-11-22 at 9 54 20 AM

It is mentioned in the docs that it is the developer's responsibility to make sure that the _tag of tagged errors used in an effect is unique... But this is super easy to miss!

What is the feature you are proposing to solve the problem?

I do understand that it is not possible to check if _tag of tagged errors used in a effect is unique or not in the compile time (I assume there is no graceful way to implement this yet in Typescript)...

I was thinking why not refuse to start the execution of a program (basically crashing it as soon as it starts) after checking if an effect uses two (or more) tagged errors with the same tag? Basically a quick check after the server starts in the dev mode... Can skip this check in the production (because servers needs to spin up as quickly as possible in production I assume).

I don't know if what I have proposed above is a graceful solution to this problem, but yesterday I encountered a flaw in business logic of my product because of tagged errors having same _tag value.

Also, If possible can you please tell me how do I handle this problem?

What alternatives have you considered?

Nothing.

Activity

  1. added
    enhancement
    on Nov 22, 2026
  2. self-assigned this
    on Nov 22, 2026
  3. KhraksMamtsov commented on Nov 22, 2026

    @KhraksMamtsov
    Contributor

    Hey! You could use [@effect/language-service](https://github.com/Effect-TS/language-service/blob/main/README.md#configuring-key-patterns).

    It provides the deterministicKeys rule, which helps prevent accidental tag collisions by enforcing deterministic naming conventions for tags.

  4. KhraksMamtsov commented on Nov 22, 2026

    @KhraksMamtsov
    Contributor

    This problem cannot be fully solved at runtime, because when the program starts, we don't know which errors it might eventually produce.

    It can be reduced to something like this:

    declare function ab(): "A" | "B"
    declare function bc(): "B" | "C"
    
    function test() {
      const ab = ab()
      const bc = bc()
      return ab === bc
    }

    At runtime, we'll only discover a collision if both functions happen to return "B". This will happen in only 1 out of 4 possible combinations.

  5. shibisuriya commented on Nov 23, 2026

    @shibisuriya
    Author

    @KhraksMamtsov thanks, I will try to integrate the LSP that you have mentioned above.

    But, since the Effect package exposes 'Data' module, why can't we use a Map or Set to make sure _tag of all instances of Data.TaggedError is unique?

    const set = new Set<_tag>()
    
    class TaggedError {
        constructor(_tag: String) {
             if(set.has(_tag)) {} // refuse to create the a instance of TaggedError in runtime...
    
             set.add(_tag)
        }
    }
    
    export * as Data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions