Change many "orelse return" sections to log.err

Beansprout will still continue gracefully, but I added handling so that
they'll log errors so we should have some record of something beind
wrong.
This commit is contained in:
Ben Buhse 2026-02-08 15:11:03 -06:00
commit 4d379a272c
No known key found for this signature in database
GPG key ID: 7916ACFCD38FD0B4
4 changed files with 37 additions and 15 deletions

View file

@ -10,14 +10,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
These are in rough order of my priority, though no promises I do them in this order.
- [ ] Switch all structs to idiomatic Zig init/deinit pattern (init returns value, caller decides stack/heap)
- [ ] Implement runtime log levels
- [ ] Support per-host config using properties
- [ ] Support per-host config using properties (maybe also per-output?)
- [ ] Add input configuration, i.e. pointer acceleration and that type of thing
- [ ] Support a basic bar
- [ ] Implement runtime log levels
- [ ] Support starting programs at WM launch
- [ ] Support overriding config location
- [ ] Add support for multimedia/brightness keys
- [ ] Make "orelse return" bits into errors; handle gracefully
- [ ] Add support for multimedia/brightness keys (this might not be neccesary)
- [ ] Support multiple seats
- [ ] Support clipping floating windows on edge of/between outputs
- [x] Support changeable primary ratio
@ -25,3 +24,6 @@ These are in rough order of my priority, though no promises I do them in this or
- [x] Support multiple outputs
- [x] Support floating windows
- [x] Support wallpapers
- [x] Make "orelse return" bits into errors; handle gracefully
- [ ] Switch all structs to idiomatic Zig init/deinit pattern (init returns value, caller decides stack/heap)
- I'm not sure I really need this

View file

@ -295,7 +295,7 @@ fn wallpaperLayerSurfaceListener(layer_surface: *zwlr.LayerSurfaceV1, event: zwl
output.configured = true;
output.renderWallpaper() catch |err| {
fatal("Wallpaper render failed: E{}", .{err});
log.err("Wallpaper render failed: {}", .{err});
};
},
.closed => {
@ -334,7 +334,7 @@ pub fn renderWallpaper(output: *Output) !void {
return;
}
// Scale our loaded image and then copy it into the Buffer's pixman.Image
const wallpaper_image = context.wallpaper_image orelse return;
const wallpaper_image = context.wallpaper_image orelse return error.MissingWallpaperImage;
const image = wallpaper_image.image;
const image_data = image.getData();
const image_width = image.getWidth();
@ -559,7 +559,6 @@ fn calculatePrimaryStackLayout(output: *Output) void {
const std = @import("std");
const assert = std.debug.assert;
const fatal = std.process.fatal;
const mem = std.mem;
const DoublyLinkedList = std.DoublyLinkedList;

View file

@ -106,7 +106,10 @@ fn seatListener(river_seat_v1: *river.SeatV1, event: river.SeatV1.Event, seat: *
// river_window_v1 needs to be optional because ev.window is optional
fn setWindowFocus(seat: *Seat, river_window_v1: ?*river.WindowV1) void {
const wv1 = river_window_v1 orelse return;
const window: *Window = @ptrCast(@alignCast(wv1.getUserData() orelse return));
const window: *Window = @ptrCast(@alignCast(wv1.getUserData() orelse {
log.err("river_window_v1 has no user data", .{});
return;
}));
seat.pending_manage.window = .{ .window = window };
}
@ -201,7 +204,10 @@ pub fn manage(seat: *Seat) void {
switch (seat.pointer_op) {
.none => {},
.move => |op| {
const output = op.window.output orelse return;
const output = op.window.output orelse {
log.err("window has no output during move operation", .{});
return;
};
const min_x = output.x;
const max_x = output.x + output.width - @as(i32, op.window.float_width);
const min_y = output.y;
@ -242,7 +248,10 @@ pub fn manage(seat: *Seat) void {
}
// Clamp position to output bounds
const output = op.window.output orelse return;
const output = op.window.output orelse {
log.err("window has no output during resize operation", .{});
return;
};
new_x = std.math.clamp(new_x, output.x, @max(output.x, output.x + output.width - new_width));
new_y = std.math.clamp(new_y, output.y, @max(output.y, output.y + output.height - new_height));

View file

@ -118,7 +118,10 @@ const XkbBinding = struct {
if (current_focus.floating) return;
// Get the first tiled window to try zoom with
const output = current_focus.output orelse return;
const output = current_focus.output orelse {
log.err("focused window has no output during zoom", .{});
return;
};
const first_tiled: *Window = blk: {
var it = output.windows.iterator(.forward);
while (it.next()) |window| {
@ -333,7 +336,10 @@ const XkbBinding = struct {
const seat = context.wm.seats.first() orelse return;
const window = seat.focused_window orelse return;
if (!window.floating) return;
const output = window.output orelse return;
const output = window.output orelse {
log.err("focused floating window has no output during move", .{});
return;
};
const min_x = output.x;
const max_x = output.x + output.width - @as(i32, window.float_width);
@ -351,7 +357,10 @@ const XkbBinding = struct {
const seat = context.wm.seats.first() orelse return;
const window = seat.focused_window orelse return;
if (!window.floating) return;
const output = window.output orelse return;
const output = window.output orelse {
log.err("focused floating window has no output during resize", .{});
return;
};
const new_width: i32 = @as(i32, window.float_width) + dw;
const new_height: i32 = @as(i32, window.float_height) + dh;
@ -373,7 +382,10 @@ const XkbBinding = struct {
fn swapWindow(context: *Context, comptime direction: enum { next, prev }) void {
const seat = context.wm.seats.first() orelse return;
const window = seat.focused_window orelse return;
const output = window.output orelse return;
const output = window.output orelse {
log.err("focused window has no output during swap", .{});
return;
};
const target = switch (direction) {
.next => output.nextWindow(window),
.prev => output.prevWindow(window),