From 5de9d27458cd8ff7e326532e8923c933e141ea7f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 9 Nov 2026 03:31:33 -0300 Subject: idioms: swallows a caller can decide on, decided: a key a macro or a repeat cannot keep is said (Macro.append returns error{OutOfMemory}), a kind's found rows and list pane say their copy's failure as their fill's, a kind word's value past its pane's 256-byte record is said instead of dropped, and the REPL ask record's two prints, which fit, are unreachable with the reason Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Kind.zig | 4 ++-- src/Macro.zig | 9 +++------ src/exec.zig | 9 +++++---- src/keys.zig | 6 +++--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Kind.zig b/src/Kind.zig index 806e9558..0a8fc7ae 100644 --- a/src/Kind.zig +++ b/src/Kind.zig @@ -971,7 +971,7 @@ fn moreFound(p: *Pardes, id: usize, rows: []const u8) void { const rp = p.panes[pane.search_pane orelse return] orelse return; const rf = if (rp.file) |*f| f else return; const o = if (rf.output) |*x| x else return; - const content = std.mem.concat(p.gpa, u8, &.{ rf.content, rows }) catch return; + const content = std.mem.concat(p.gpa, u8, &.{ rf.content, rows }) catch |err| return p.reportError(id, "found", err); pardes.panes.Output.fillResults(p, id, std.fs.path.dirname(rf.path) orelse p.sessionDir(), .search, o.arg(), content, null) catch |err| p.reportError(id, "found", err); } @@ -1137,7 +1137,7 @@ pub var seed_base: u64 = 0; /// kind's pane, a Look of one going to its kind (look.zig lookKind). fn textPane(p: *Pardes, id: usize, slot: *const Slot, name: []const u8, text: []const u8) void { const dir = std.fs.path.dirname(slot.path) orelse p.sessionDir(); - const content = p.gpa.dupe(u8, text) catch return; + const content = p.gpa.dupe(u8, text) catch |err| return p.reportError(id, name, err); pardes.panes.Output.fillResults(p, id, dir, .kind, name, content, null) catch |err| p.reportError(id, name, err); } diff --git a/src/Macro.zig b/src/Macro.zig index b619e523..3688dcf9 100644 --- a/src/Macro.zig +++ b/src/Macro.zig @@ -59,14 +59,11 @@ pub fn deinit(m: *Macro, gpa: std.mem.Allocator) void { /// A typed key, each of its characters one key: what a host delivers as /// one key event with a run of text is that run typed. -pub fn append(list: *std.ArrayList(Stored), gpa: std.mem.Allocator, key: Key) void { +pub fn append(list: *std.ArrayList(Stored), gpa: std.mem.Allocator, key: Key) error{OutOfMemory}!void { const view = std.unicode.Utf8View.init(key.text) catch null; - if (key.text.len == 0 or key.ctrl or key.alt or view == null) { - list.append(gpa, .of(key)) catch {}; - return; - } + if (key.text.len == 0 or key.ctrl or key.alt or view == null) return list.append(gpa, .of(key)); var it = view.?.iterator(); - while (it.nextCodepoint()) |cp| list.append(gpa, .{ .cp = cp, .shift = key.shift }) catch {}; + while (it.nextCodepoint()) |cp| try list.append(gpa, .{ .cp = cp, .shift = key.shift }); } const names = [_]struct { cp: u21, name: []const u8 }{ diff --git a/src/exec.zig b/src/exec.zig index c636cc7c..93f524cf 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -529,8 +529,8 @@ fn routeToRepl(p: *Pardes, from: usize, text: []const u8) Routed { p.view().active = from; var rec: [96]u8 = undefined; var rw = std.Io.Writer.fixed(&rec); - rw.print("{d} repl", .{src.serial}) catch {}; - for (bound[0..n]) |i| rw.print(" {c}", .{p.panes[i].?.repl.?.letter}) catch {}; + rw.print("{d} repl", .{src.serial}) catch unreachable; // a u32 and bound's 26 letters fit 96 + for (bound[0..n]) |i| rw.print(" {c}", .{p.panes[i].?.repl.?.letter}) catch unreachable; pardes.ctlfs.events.notePath(p, "ask", rw.buffered()); return .asked; } @@ -1251,8 +1251,9 @@ pub fn runWord(p: *Pardes, id: usize, w: *const pardes.Kind.Word, line: []const var next: pardes.Kind.Buf(256) = .{}; var out: std.Io.Writer = .fixed(&next.bytes); var lines = std.mem.tokenizeScalar(u8, s.values.slice(), '\n'); - while (lines.next()) |l| if (!std.mem.eql(u8, l[0 .. std.mem.indexOfScalar(u8, l, ' ') orelse l.len], name)) out.print("{s}\n", .{l}) catch return; - out.print("{s} {s}\n", .{ name, arg }) catch return; + const full = std.fmt.bufPrint(&said, "{s}: the pane's values are past {d} bytes: not kept", .{ name, next.bytes.len }) catch name; + while (lines.next()) |l| if (!std.mem.eql(u8, l[0 .. std.mem.indexOfScalar(u8, l, ' ') orelse l.len], name)) out.print("{s}\n", .{l}) catch return p.reportFailure(id, full); + out.print("{s} {s}\n", .{ name, arg }) catch return p.reportFailure(id, full); next.len = @intCast(out.buffered().len); s.values = next; } diff --git a/src/keys.zig b/src/keys.zig index 5be3a110..c197940e 100644 --- a/src/keys.zig +++ b/src/keys.zig @@ -153,7 +153,7 @@ pub fn answerQuestion(p: *Pardes, id: usize, choice: ?u8) bool { pub fn handleKey(p: *Pardes, key: Key) void { // A double-click is two clicks with nothing between them. p.view().last_click = null; - if (p.macro.recording != 0 and p.macro.replaying == 0) Macro.append(&p.macro.recorded, p.gpa, key); + if (p.macro.recording != 0 and p.macro.replaying == 0) Macro.append(&p.macro.recorded, p.gpa, key) catch |err| p.reportError(p.view().active, "macro", err); // A question waiting on a pane takes the next key, whatever mode the // pane or a header edit is in: that key is its answer. for (p.panes, 0..) |slot, id| { @@ -414,7 +414,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { const m = &p.macro; switch (was) { .normal => { - Macro.append(&m.command, p.gpa, key); + Macro.append(&m.command, p.gpa, key) catch |err| p.reportError(p.view().active, "macro", err); if (t.mode == .insert) { m.last_insert.clearRetainingCapacity(); m.last_insert.appendSlice(p.gpa, m.command.items) catch |err| p.reportError(p.view().active, "macro", err); @@ -424,7 +424,7 @@ pub fn handleKey(p: *Pardes, key: Key) void { } else if (std.meta.eql(t.normal, modal.Normal.State{})) m.command.clearRetainingCapacity(); }, .insert => if (m.inserting) { - Macro.append(&m.last_insert, p.gpa, key); + Macro.append(&m.last_insert, p.gpa, key) catch |err| p.reportError(p.view().active, "macro", err); if (t.mode != .insert) m.inserting = false; }, .tty => {}, -- cgit v1.3