feat: use explicit error handling for all startup errors

This commit is contained in:
CJ van den Berg 2025-03-25 17:12:01 +01:00
parent fc3224137d
commit a1b2737c5d
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
12 changed files with 116 additions and 50 deletions

View file

@ -8,13 +8,17 @@ const Plane = @import("renderer").Plane;
pub const Style = enum { none, grip };
pub fn create(allocator: std.mem.Allocator, parent: Plane, config: []const u8, style: Style, event_handler: ?EventHandler) !Widget {
pub fn create(allocator: std.mem.Allocator, parent: Plane, config: []const u8, style: Style, event_handler: ?EventHandler) error{OutOfMemory}!Widget {
var w = try WidgetList.createH(allocator, parent, "statusbar", .{ .static = 1 });
if (style == .grip) w.after_render = render_grip;
w.ctx = w;
var it = std.mem.splitScalar(u8, config, ' ');
while (it.next()) |widget_name|
try w.add(try status_widget.create(widget_name, allocator, w.plane, event_handler) orelse continue);
while (it.next()) |widget_name| {
try w.add(status_widget.create(widget_name, allocator, w.plane, event_handler) catch |e| switch (e) {
error.OutOfMemory => return error.OutOfMemory,
error.WidgetInitFailed => null,
} orelse continue);
}
return w.widget();
}