Show UI errors in info line again

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2026-02-12 11:20:54 +01:00
parent 32d5330efb
commit 01dcfa207e
3 changed files with 48 additions and 6 deletions

View File

@@ -10,11 +10,20 @@ const ErrorHandler = packed struct {
const SharedError = @This();
data: []align(std.heap.page_size_min) u8,
write_error_event_fn: ?*const fn (anyerror, *anyopaque) anyerror!void,
ctx: ?*anyopaque,
pub fn init() !SharedError {
pub fn init(
write_error_event_fn: ?*const fn (anyerror, *anyopaque) anyerror!void,
ctx: ?*anyopaque,
) !SharedError {
const data = try std.posix.mmap(null, @sizeOf(ErrorHandler), std.posix.PROT.READ | std.posix.PROT.WRITE, .{ .TYPE = .SHARED, .ANONYMOUS = true }, -1, 0);
return .{ .data = data };
return .{
.data = data,
.write_error_event_fn = write_error_event_fn,
.ctx = ctx,
};
}
pub fn deinit(self: *SharedError) void {
@@ -25,6 +34,10 @@ pub fn writeError(self: SharedError, err: anyerror) void {
var buf_stream = std.io.fixedBufferStream(self.data);
const writer = buf_stream.writer();
writer.writeStruct(ErrorHandler{ .has_error = true, .err_int = @intFromError(err) }) catch {};
if (self.write_error_event_fn) |write_error_event_fn| {
@call(.auto, write_error_event_fn, .{ err, self.ctx.? }) catch {};
}
}
pub fn readError(self: SharedError) ?anyerror {