Skip to content

ability to resolve partially known error sets #3311

Closed

Description

@kaizoplant

sometimes i run into the case where i have an error set like

KnownError || UnknownError()

it would be helpful if it was possible that this would be recognized as some error set and maybe also allow autocompletions with an error that was part of KnownError.
idk if this is actually a feasible task, but i think it would be cool if it was possible.

Activity

  1. techatrix commented on Nov 4, 2026

    @techatrix
    Member

    That seems like a very reasonable feature. We should be able to represent an error set that contains errors that could not be resolved:

    error{A} || error{B} // error{ A, B }
    error{A} || unknown // error{ A, ... }
    unknown || error{B} // error{ B, ... }
    unknown || unknown // error{ ... }

    unknown may be any expression that doesn't resolve to an error set.

    Related source code

    Error sets are represented in the "InternPool" data structure and currently store a list of all error names:

    pub const ErrorSet = struct {
    owner_decl: Decl.OptionalIndex,
    names: StringSlice,
    };

    This should be extended to have a boolean flag that specifies whether there also are unknown errors.

    The logic for the lhs || rhs is implemented in errorSetMerge:

    pub fn errorSetMerge(ip: *InternPool, a_ty: Index, b_ty: Index) Allocator.Error!Index {

    This should be extended to not assume that the lhs and rhs are errors sets but also accept an unknown value/type (see isUnknown). All call sites to this function should be updated accordingly to not abort early when lhs or rhs coudn't be resolve to an error set.

    Test coverage should be added to tests/analysis/error_union.zig.

  2. iwami4438 commented on Nov 6, 2026

    @iwami4438
    Contributor

    Hello.
    May I take this on?

  3. techatrix commented on Nov 8, 2026

    @techatrix
    Member

    Hello. May I take this on?

    Yes. You are welcome to work on this. Have a look at the contributing guide if you haven't already on how to get started.

  4. linked a pull request that will close this issueFeat: add known error sets #3319on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions