Skip to content

refactor: migrate the examples to fallible view and init - #141

Merged
meszmate merged 1 commit into
mainfrom
refactor/fallible-example-views
Aug 14, 2026
Merged

meszmate merged 1 commit into
mainfrom
refactor/fallible-example-views

Conversation

@meszmate

Copy link
Copy Markdown
Owner

Stacked on #132.

Item 3 from the review.

418 of the 521 catch sites in examples/ are gone. Every one of them was a rendering fallback that turned an allocation failure into output a user cannot tell apart from real content — a "?" where a number belongs, a title that silently loses its styling, a whole frame replaced by the word "Error".

-        const title = title_style.render(ctx.allocator, "Todo List") catch "Todo List";
-        const filter_text = std.fmt.allocPrint(ctx.allocator, "Filter: {s}", .{...}) catch "Filter:";
-        writer.writeAll(styled_filter) catch {};
+        const title = try title_style.render(ctx.allocator, "Todo List");
+        const filter_text = try std.fmt.allocPrint(ctx.allocator, "Filter: {s}", .{...});
+        try writer.writeAll(styled_filter);

Every view that had such a fallback now returns ![]const u8. init bodies that dropped registrations on the floor were migrated too — showcase.zig alone had 28 of these:

-        self.table.addRow(.{ "web-01", "online", "45d 3h", "0.42" }) catch {};
+        try self.table.addRow(.{ "web-01", "online", "45d 3h", "0.42" });

A row that fails to be added is a bug, not a display variation.

What was deliberately left alone

catch return .none in update, the file-open failures in file_browser, catch unreachable where a call genuinely cannot fail. Those are error handling, not fallbacks — 103 sites, and they stay.

How it was done, and how it was checked

Mechanically, then reviewed. The transform only touched catch <value> and catch {}, never catch return / catch continue / catch |err|. Verified afterwards that:

  • the diff contains no removed line matching catch (return|break|continue|\|) — no control flow was rewritten
  • no try landed inside a string literal or a comment (three comments that a regex pass did mangle were repaired)
  • no try try, no try in a syntactically odd position
  • zig build, zig build test, and zig build test -Doptimize=ReleaseSafe are all clean

42 files, 566 insertions, 566 deletions — every changed line is one of the two shapes above.

@meszmate
meszmate force-pushed the refactor/fallible-example-views branch from 1359fc5 to cf777cb Compare August 14, 2026 03:40
@meszmate
meszmate force-pushed the feat/fallible-model-callbacks branch from 1fb58a9 to 7d94d85 Compare August 14, 2026 04:37
@meszmate
meszmate changed the base branch from feat/fallible-model-callbacks to main August 14, 2026 04:42
418 of the 521 `catch` sites in examples/ are gone -- every one of them
a rendering fallback that turned an allocation failure into output the
user cannot distinguish from real content: a "?" where a number belongs,
a title that silently loses its styling, a whole frame replaced by the
word "Error".

Every `view` that had such a fallback now returns `![]const u8`, and
`init` bodies that dropped registrations on the floor
(`table.addRow(...) catch {}`, `help.addBinding(...) catch {}`) now
propagate.

What is left is deliberate: `catch return .none` in update, the file
open failures in file_browser, `catch unreachable` where the call
genuinely cannot fail. Those are error handling, not fallbacks.
@meszmate
meszmate force-pushed the refactor/fallible-example-views branch from cf777cb to 2c399c1 Compare August 14, 2026 04:44
@meszmate
meszmate merged commit f0da9cc into main Aug 14, 2026
12 checks passed
@meszmate
meszmate deleted the refactor/fallible-example-views branch August 28, 2026 12:09
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