Skip to content

How to return error with message or there is a better way? #15892

@tisonkun

Description

@tisonkun

Based on my previous programming experience, it's common that I define a set of error codes and errors are constructed with a code with a detailed message.

It seems Zig provides error set enums to fit the error code part, while I don't know how to return errors with messages. Or it's Zig's best practice to representing errors fully by codes.

A real-world example is that - when I'm parsing a specific config file, I'd like to distinguish parsing errors and IO errors, but what exactly the parsing error is is not significant. While I still need to tell the caller about the details of the parsing error, the control flow is the same for all of them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions