Skip to content

Fix: Remove error union from Program.init*#107

Open
IridescentRose wants to merge 1 commit into
meszmate:mainfrom
IridescentRose:fix/empty_error_union
Open

Fix: Remove error union from Program.init*#107
IridescentRose wants to merge 1 commit into
meszmate:mainfrom
IridescentRose:fix/empty_error_union

Conversation

@IridescentRose
Copy link
Copy Markdown
Contributor

While writing my TUI application I noticed my refactored main had some code that looked like it shouldn't compile:

pub fn main(init: std.process.Init) u8 {
    // ...
    var program = try zz.Program(tui.Model).initWithOptions(
        arena.allocator(),
        init.io,
        init.environ_map,
        .{
            .kitty_keyboard = true,
            .bracketed_paste = true,
            .title = "Hanabi",
            .alt_screen = true,
        },
    );
    // ...
    return 0;
}

try without !u8 as the return type should fail in most contexts; The reason it doesn't here is because the error set is {} -- there are no possible errors from the code path.

Checking init, nothing currently throws an error, it's all infallible struct initialization. Reflecting this appropriately in the type signature keeps the API honest to the real behavior, as it currently is impossible to throw an error. If at some point this changes, error-unions can be reintroduced then.

@IridescentRose IridescentRose force-pushed the fix/empty_error_union branch from af22ab9 to 78efdf0 Compare May 11, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant