feat: use explicit error handling for all startup errors
This commit is contained in:
parent
fc3224137d
commit
a1b2737c5d
12 changed files with 116 additions and 50 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,14 +19,20 @@ tz: zeit.timezone.TimeZone,
|
|||
const Self = @This();
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) @import("widget.zig").CreateError!Widget {
|
||||
var env = std.process.getEnvMap(allocator) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||
var env = std.process.getEnvMap(allocator) catch |e| {
|
||||
std.log.err("clock: std.process.getEnvMap failed with {any}", .{e});
|
||||
return error.WidgetInitFailed;
|
||||
};
|
||||
defer env.deinit();
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = .{
|
||||
.allocator = allocator,
|
||||
.plane = try Plane.init(&(Widget.Box{}).opts(@typeName(Self)), parent),
|
||||
.on_event = event_handler,
|
||||
.tz = zeit.local(allocator, &env) catch |e| return tp.exit_error(e, @errorReturnTrace()),
|
||||
.tz = zeit.local(allocator, &env) catch |e| {
|
||||
std.log.err("clock: zeit.local failed with {any}", .{e});
|
||||
return error.WidgetInitFailed;
|
||||
},
|
||||
};
|
||||
try tui.message_filters().add(MessageFilter.bind(self, receive_tick));
|
||||
self.update_tick_timer(.init);
|
||||
|
|
|
@ -35,7 +35,7 @@ pub fn create(allocator: std.mem.Allocator, parent: Plane, event_handler: ?Event
|
|||
};
|
||||
logview.init(allocator);
|
||||
try tui.message_filters().add(MessageFilter.bind(self, receive_log));
|
||||
try log.subscribe();
|
||||
log.subscribe() catch return error.WidgetInitFailed;
|
||||
return Widget.to(self);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ const widgets = std.static_string_map.StaticStringMap(CreateFunction).initCompti
|
|||
.{ "keybind", @import("keybindstate.zig").create },
|
||||
.{ "tabs", @import("tabs.zig").create },
|
||||
});
|
||||
pub const CreateError = error{ OutOfMemory, Exit };
|
||||
pub const CreateError = error{ OutOfMemory, WidgetInitFailed };
|
||||
pub const CreateFunction = *const fn (allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) CreateError!Widget;
|
||||
|
||||
pub fn create(name: []const u8, allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) CreateError!?Widget {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue