Tagged union as `error` type

What is the most idiomatic “Zig” way of doing something like that:

    pub const Error = error {
        FAILED_TO_PARSE: Info,
        UNDEFINED_SYMBOL: []const u8,
        NO_OPERAND: Loc,
        INVALID_TYPE: []const u8,
    };

Error sets cannot have extra values.

To overcome the limitation you can either:

  • Don’t use errors for your parsing functions, return a union with your error structure, or
  • Use errors and pass an extra parameter with your error structure.
1 Like

oh, that’s understandable. Thank you

1 Like