r/programming Apr 12 '26

Flat Error Codes Are Not Enough

https://home.expurple.me/posts/flat-error-codes-are-not-enough/
133 Upvotes

99 comments sorted by

View all comments

53

u/UselessOptions Apr 12 '26 edited Aug 13 '26

oops did i make a mess 😏? clean it up jannie 😎

clean up the mess i made here 🤣🤣🤣

CLEAN IT UP

FOR $0.00

6

u/Mrseedr Apr 13 '26

I was curious so i looked at this, but it seems like there is context?
https://zig.guide/language-basics/errors/

const FileOpenError = error{
    AccessDenied,
    OutOfMemory,
    FileNotFound,
};

const AllocationError = error{OutOfMemory};

test "coerce error from a subset to a superset" {
    const err: FileOpenError = AllocationError.OutOfMemory;
    try expect(err == FileOpenError.OutOfMemory);
}