From 9b60771ffcd254772b716fafe488b09d9c2d3e0c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 12:15:23 -0300 Subject: idioms #16, edits fail by name: the edit operations return edit.Error (memory, or a terminal's rows not read) and try where they caught and returned, so the key, chord or paste that ran one says the failure (`edit: out of memory`, reportError) where it did nothing; look, Core, File and terminal say theirs the same way, and the prints whose buffer provably fits catch unreachable with why Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Core.zig | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/Core.zig') diff --git a/src/Core.zig b/src/Core.zig index a595e6b0..c7d2fd48 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -530,8 +530,8 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { if (made) |_| { if (opts.file_line > 0) { var said: pardes.Kind.Buf(160) = .{}; - var place: [16]u8 = undefined; - _ = pardes.Kind.address(p, 0, std.fmt.bufPrint(&place, "{d}", .{opts.file_line}) catch "", &said); + var place: [20]u8 = undefined; + _ = pardes.Kind.address(p, 0, std.fmt.bufPrint(&place, "{d}", .{opts.file_line}) catch unreachable, &said); // a usize } } else |_| {} break :initial_doc made; @@ -821,7 +821,7 @@ pub fn setLastDump(p: *Pardes, path: []const u8) void { /// text) has the old path swapped, never left pointing at a dump that is /// not the last. pub fn pointRestoreAt(p: *Pardes, path: []const u8) void { - const copy = p.gpa.dupe(u8, path) catch return; + const copy = p.gpa.dupe(u8, path) catch |err| return p.reportError(p.view().active, "Restore", err); if (p.last_dump) |old| { if (p.global_tag.own) |own| swap: { const a = p.scratch.allocator(); @@ -894,13 +894,13 @@ pub fn parkPendingWrite(p: *Pardes, id: usize, bytes: []const u8) void { // Compact what the drain already sent before growing: a burst that // arrives in pieces must not keep re-copying bytes nobody wants. const keep = pw.bytes.len - pw.off; - const grown = p.gpa.alloc(u8, keep + bytes.len) catch return; + const grown = p.gpa.alloc(u8, keep + bytes.len) catch |err| return p.reportError(id, "write", err); @memcpy(grown[0..keep], pw.bytes[pw.off..]); @memcpy(grown[keep..], bytes); p.gpa.free(pw.bytes); pw.* = .{ .bytes = grown }; } else { - p.pending_write[id] = .{ .bytes = p.gpa.dupe(u8, bytes) catch return }; + p.pending_write[id] = .{ .bytes = p.gpa.dupe(u8, bytes) catch |err| return p.reportError(id, "write", err) }; } p.pending_write_bytes += bytes.len; } @@ -1299,7 +1299,7 @@ fn sayShellFailure(p: *Pardes, id: u8, err: anyerror) void { var said: [320]u8 = undefined; var interp: [256]u8 = undefined; const name = tape.value(.interpreter, missingInterpreter, .{ pane.shell orelse p.shellBin(), &interp }); - p.reportFailure(id, if (name) |n| std.fmt.bufPrint(&said, "shell: interpreter {s} not found", .{n}) catch "shell: interpreter not found" else "shell: interpreter not found"); + p.reportFailure(id, if (name) |n| std.fmt.bufPrint(&said, "shell: interpreter {s} not found", .{n}) catch unreachable else "shell: interpreter not found"); } else { p.reportError(id, "shell", err); } @@ -1338,12 +1338,13 @@ pub fn saveFailed(p: *Pardes, id: u8, path: []const u8, err: anyerror) void { // A write into a directory that is not there: said so, in the words // a mount reads as ENOENT; EACCES when one above refuses. const parent = parentTrouble(path, err); + const shown = path[0..@min(path.len, limits.host_path_cap)]; // what fits `what` if (parent.denied) - p.reportFailure(id, std.fmt.bufPrint(&what, "Save {s}: permission denied", .{path}) catch "Save: permission denied") + p.reportFailure(id, std.fmt.bufPrint(&what, "Save {s}: permission denied", .{shown}) catch unreachable) else if (parent.missing) - p.reportFailure(id, std.fmt.bufPrint(&what, "Save {s}: no such directory", .{path}) catch "Save: no such directory") + p.reportFailure(id, std.fmt.bufPrint(&what, "Save {s}: no such directory", .{shown}) catch unreachable) else - p.reportError(id, std.fmt.bufPrint(&what, "Save {s}", .{path}) catch "Save", err); + p.reportError(id, std.fmt.bufPrint(&what, "Save {s}", .{shown}) catch unreachable, err); p.noteLateFailure(id); } @@ -1355,17 +1356,17 @@ pub fn dumpFailed(p: *Pardes, path: []const u8, err: anyerror) void { const taped = tape.enter(p, .{ .dump_failed = .{ .path = path, .err = err } }); defer tape.leave(p, taped); var what: [limits.host_path_cap + 8]u8 = undefined; - const operation = std.fmt.bufPrint(&what, "Dump {s}", .{path}) catch "Dump"; + const operation = std.fmt.bufPrint(&what, "Dump {s}", .{path[0..@min(path.len, limits.host_path_cap)]}) catch unreachable; // Into a DumpDir that is not there: said so, ENOENT, as a Save is; // one that is there but no directory (`/dev/null`) says that. const parent = parentTrouble(path, err); var said: [limits.host_path_cap + 48]u8 = undefined; if (parent.denied and parent.kind == null) - p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}: permission denied", .{operation}) catch "Dump: permission denied") + p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}: permission denied", .{operation}) catch unreachable) // `what` and 19 bytes else if (parent.kind != null and parent.kind != .directory) p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}: {s} is not a directory", .{ operation, parent.dir }) catch "Dump: not a directory") else if (parent.missing) - p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}: no such directory", .{operation}) catch "Dump: no such directory") + p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}: no such directory", .{operation}) catch unreachable) else p.reportError(v.active, operation, err); // In the words the message row has, so the write's err is the one @@ -1618,7 +1619,7 @@ pub fn update(p: *Pardes, ev: Event) void { .mouse => |m| mouse.handleMouse(p, m), .paste => |bytes| { p.typedInto(); - edit.applyPaste(p, bytes); + edit.applyPaste(p, bytes) catch |err| p.reportError(v.active, "paste", err); }, .command => |line| _ = p.executeBuiltinLine(v.active, line), .focus => |focused| { @@ -1734,7 +1735,7 @@ pub fn windowOpacityDone(p: *Pardes, applied: u8, failure: ?[]const u8) void { // the same command will arm a new request. p.settings.window_opacity = applied; var buf: [256]u8 = undefined; - p.setMessage(p.view().active, std.fmt.bufPrint(&buf, "WindowOpacity: {s}", .{reason[0..@min(reason.len, 240)]}) catch "WindowOpacity: compositor rejected the request"); + p.setMessage(p.view().active, std.fmt.bufPrint(&buf, "WindowOpacity: {s}", .{reason[0..@min(reason.len, 240)]}) catch unreachable); // 255 bytes } /// Recompute geometry, push grid-size changes to each emulator and pty, @@ -1747,7 +1748,7 @@ pub fn sync(p: *Pardes) void { // again: one logged or answered names this pane for good. Its // rows, if it had any, go where a closed pane's go; no other // pane moves (a pane dragged short keeps its rows). - if (p.panes[id] != null) p.removePane(id, null) catch {}; + if (p.panes[id] != null) p.removePane(id, null) catch |err| p.reportError(v.active, "open", err); } // A file opened or closed this step: the kept list follows. p.saveRecent(); -- cgit v1.3