summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-09 03:29:30 -0300
committerGabriel Schneider <[email protected]>2026-11-09 03:30:37 -0300
commit446292e15d56c9c248dae5d6fde1be3a83ade82e (patch)
tree859d8be8a92a18011034e614324fa1af5c99139e
parentaabbccba49772cf73c7e35ae470245e9fda9d6ff (diff)
downloadpardes-446292e15d56c9c248dae5d6fde1be3a83ade82e.tar.gz
pardes-446292e15d56c9c248dae5d6fde1be3a83ade82e.zip
idioms: the 9P tree's swallows decided: a directory read stages every entry or answers ENOMEM (stageDirent and sources.stage return error{OutOfMemory}, readdir's entries made by stageDir, an /os listing whose buffer fills ends there), a pane's tag read through tagOf fails by name (a read or an event write answers ENOMEM, a stat's length and ctl's line say 0), a pane that cannot close (removePane's nine swallowing callers) and a /pager text that cannot go in (fillClosedPagers) are said on their pane, and Queue.push says once why a lost record is not said
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/Query.zig8
-rw-r--r--src/Store.zig2
-rw-r--r--src/exec.zig4
-rw-r--r--src/fs.zig3
-rw-r--r--src/ninep/ctl.zig10
-rw-r--r--src/ninep/events.zig7
-rw-r--r--src/ninep/pane.zig8
-rw-r--r--src/ninep/sources.zig6
-rw-r--r--src/ninep/tree.zig47
9 files changed, 54 insertions, 41 deletions
diff --git a/src/Query.zig b/src/Query.zig
index c05992f6..b1424968 100644
--- a/src/Query.zig
+++ b/src/Query.zig
@@ -1671,7 +1671,7 @@ fn makePreview(p: *Pardes, qid: usize, rows: u16, giver: usize) ?usize {
};
layout.compute(p);
if (!layout.attachFrom(p, qid, free, rows, giver)) {
- p.removePane(free, qid) catch {};
+ p.removePane(free, qid) catch |err| p.reportError(qid, "query", err);
return null;
}
rp.query.?.preview = np.serial;
@@ -1905,7 +1905,7 @@ pub fn cancel(p: *Pardes, id: usize) void {
// go to the text whose rows they were.
if (previewOf(p, id)) |pid| {
p.panes[pid].?.attached_to = null;
- p.removePane(pid, owner_id) catch {};
+ p.removePane(pid, owner_id) catch |err| p.reportError(id, "query", err);
q.preview = 0;
}
const f = &rp.file.?;
@@ -1936,10 +1936,10 @@ pub fn cancel(p: *Pardes, id: usize) void {
// Attached, its rows go back to its owner; else to its own column's.
const attached = layout.ownerOf(p, id) != null;
if (owner_id) |oid| {
- p.removePane(id, if (attached) oid else null) catch {};
+ p.removePane(id, if (attached) oid else null) catch |err| p.reportError(id, "query", err);
p.view().active = oid;
if (layout.findPane(p, oid)) |at| p.setActiveColumn(at.col);
- } else p.removePane(id, null) catch {};
+ } else p.removePane(id, null) catch |err| p.reportError(id, "query", err);
}
/// A parse of pane `serial`'s text came back (Stream.receiveParse): its
diff --git a/src/Store.zig b/src/Store.zig
index 61678be6..8b8db030 100644
--- a/src/Store.zig
+++ b/src/Store.zig
@@ -212,7 +212,7 @@ pub fn reopen(s: *Store, p: *Pardes, serial: u32, from: usize) bool {
false;
if (!placed) exec.placeNew(p, from, from, free, .doc);
if (layout.findPane(p, free) == null) {
- p.removePane(free, null) catch {};
+ p.removePane(free, null) catch |err| p.reportError(from, "reopen", err);
return false;
}
// No room anywhere: refused, it closes at the step's end, still listed.
diff --git a/src/exec.zig b/src/exec.zig
index 8e96be80..c636cc7c 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -419,7 +419,7 @@ fn refusedPlacement(p: *Pardes, id: usize) bool {
p.unplaced.unset(id);
// It held no weight (placeNew put every pane's rows back as they
// were): nothing else moves, a pane dragged short included.
- p.removePane(id, null) catch {};
+ p.removePane(id, null) catch |err| p.reportError(id, "open", err);
return true;
}
@@ -847,7 +847,7 @@ pub fn commandDone(p: *Pardes, id: usize, status: ?u8) void {
// failure is worth the pane.
if (pane.command_pages) {
pane.command_pages = false;
- if (status == 0) return p.removePane(id, null) catch {};
+ if (status == 0) return p.removePane(id, null) catch |err| p.reportError(id, "close", err);
}
var buf: [16]u8 = undefined;
const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16
diff --git a/src/fs.zig b/src/fs.zig
index 8e7ec346..a0092991 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -249,7 +249,8 @@ fn osListing(io: std.Io, path: []const u8, off: u64, size: u32, listing: *[16 *
continue;
}
const node = if (std.mem.eql(u8, normalized.path, "/")) os_root else os_node | (std.hash.Wyhash.hash(0, normalized.path) & (os_node - 1));
- tree.stageDirent(&listed, fixed.allocator(), node, child.kind == .directory, entry.name);
+ // The listing's buffer is full: it ends here, the next read goes on.
+ tree.stageDirent(&listed, fixed.allocator(), node, child.kind == .directory, entry.name) catch break;
if (listed.items.len >= @max(size, 512)) break;
}
return listed.items;
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 2e362f77..ce92ba30 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -228,7 +228,7 @@ pub fn command(p: *Pardes, req: Req, serial: ?u32, exec: bool, in_tag: bool) Rep
}
if (p.panes[id] == null) return Reply.fail(req.tag, E.NOENT);
defer if (scratch) |s| if (v.active != s) if (p.panes[s]) |sp| if (sp.file) |f| {
- if (f.content.len == 0) p.removePane(s, null) catch {};
+ if (f.content.len == 0) p.removePane(s, null) catch |err| p.reportError(s, "exec", err);
};
p.fs.ran_at = p.panes[id].?.serial;
p.fs.no_pane_slot = false;
@@ -424,7 +424,7 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: *[pane_text_cap]u8) []const u8 {
fill: {
w.print("{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} ", .{
pane.serial,
- pane_files.tagOf(p, pane).len,
+ if (pane_files.tagOf(p, pane)) |tag| tag.len else |_| 0, // a length, as a stat's: none when the tag cannot be made
// A terminal's body is its history, read whole on an open's first read.
if (pane.isTerminal()) panes.terminal.screenTextLen(pane) else pane_files.bodyOf(pane).len,
// A directory pane is one, as acme's isdir says.
@@ -722,7 +722,7 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM
const keyboard = p.view().active;
if (panes.Output.openDiff(p, id, f.path, f.content)) |hid| {
// ponytail: the text is gone with it; Diff on the +Diff says no such file.
- p.removePane(id, hid) catch {};
+ p.removePane(id, hid) catch |err| p.reportError(id, "pager", err);
} else |_| {}
if (p.panes[keyboard] != null) p.view().active = keyboard;
}
@@ -731,7 +731,7 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM
/// The editor's step: the text of /pager opens closed unread goes in.
pub fn fillClosedPagers(p: *Pardes) void {
for (p.fs.pages.items) |*page| {
- fillPager(p, page.serial, &page.bytes) catch {};
+ fillPager(p, page.serial, &page.bytes) catch |err| if (p.paneBySerial(page.serial)) |id| p.reportError(id, "pager", err);
page.bytes.deinit(p.gpa);
}
p.fs.pages.clearRetainingCapacity();
@@ -1359,7 +1359,7 @@ test "pane ctl read is acme's fields -- index's five, width in cells, font, tab
var want: std.ArrayList(u8) = .empty;
defer want.deinit(gpa);
try want.print(gpa, "{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {s} {d:>11} {d:>11} {d:>11} current mode:normal ", .{
- pane.serial, pane_files.tagOf(p, pane).len, @as(usize, 2), 0, 0, pane.cols, "default", config.tab_now, 0, 0,
+ pane.serial, (try pane_files.tagOf(p, pane)).len, @as(usize, 2), 0, 0, pane.cols, "default", config.tab_now, 0, 0,
});
try testing.expectEqualStrings(want.items, a.bytes);
try testing.expectEqual(@as(u64, a.bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = Node.of(pane.serial, .ctl) }).reply.attr.size);
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 20cb4e6e..77a4e35f 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -39,6 +39,9 @@ pub const Queue = struct {
q.head = 0;
}
+ /// With no memory for it the record is lost, as one pushed out of a
+ /// full ring is: its callers have nowhere to say so (the log is one of
+ /// these rings, and an event or pty reader is told by what it reads).
pub fn push(q: *Queue, gpa: std.mem.Allocator, record: []const u8) void {
if (record.len > std.math.maxInt(u32)) return;
while (q.buf.items.len - q.head + record.len + 4 > q.cap) {
@@ -712,7 +715,7 @@ pub fn writeEvent(p: *Pardes, asked: Req, id: usize) Reply {
const serial = pane0.serial;
{
const body = pane_files.bodyOf(pane0);
- const tag = pane_files.tagOf(p, pane0);
+ const tag = pane_files.tagOf(p, pane0) catch return Reply.fail(req.tag, E.NOMEM);
var check: EventReader = .{ .data = req.data };
while (check.next()) |r| {
// Who made it: E, F, K or M, as acme's records say.
@@ -738,7 +741,7 @@ pub fn writeEvent(p: *Pardes, asked: Req, id: usize) Reply {
while (run.next()) |r| {
const live = p.paneBySerial(serial) orelse break;
const pane = p.panes[live].?;
- const whole = if (r.action.onTag()) pane_files.tagOf(p, pane) else pane_files.bodyOf(pane);
+ const whole = if (r.action.onTag()) pane_files.tagOf(p, pane) catch return Reply.fail(req.tag, E.NOMEM) else pane_files.bodyOf(pane);
const lo = @min(@as(usize, r.q0), whole.len);
const hi = @max(lo, @min(@as(usize, r.q1), whole.len));
// An empty range with no text is a click at that point: expanded as
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 519e5333..ce246465 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -131,8 +131,8 @@ pub fn fileOf(pane: *Pane) ?*panes.File.State {
return if (pane.file) |*f| f else null;
}
-pub fn tagOf(p: *Pardes, pane: *Pane) []const u8 {
- return tagline.tagText(p, p.scratch.allocator(), pane) catch "";
+pub fn tagOf(p: *Pardes, pane: *Pane) error{OutOfMemory}![]const u8 {
+ return tagline.tagText(p, p.scratch.allocator(), pane);
}
pub fn dirtyOf(pane: *const Pane) bool {
@@ -320,7 +320,7 @@ pub fn fileSize(p: *Pardes, id: usize, f: PaneFile) u64 {
// What addr selects, generated by each read: no length, as acme's
// data and xdata have none.
.data, .xdata => 0,
- .tag => tagOf(p, pane).len,
+ .tag => if (tagOf(p, pane)) |tag| tag.len else |_| 0, // a stat's length is a hint: none when the tag cannot be made
.name => nameOf(p, pane).len + 1,
.ctl => ctl: {
var buf: [ctl.pane_text_cap]u8 = undefined;
@@ -374,7 +374,7 @@ pub fn read(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply
.body => readBody(p, req, id, pane),
.tag => tag: {
applyTagTruncation(p, pane);
- break :tag tree.window(p, req, tagOf(p, pane));
+ break :tag tree.window(p, req, tagOf(p, pane) catch break :tag Reply.fail(req.tag, E.NOMEM));
},
.ctl => ctl: {
var buf: [ctl.pane_text_cap]u8 = undefined;
diff --git a/src/ninep/sources.zig b/src/ninep/sources.zig
index 32edb1f6..2e96b539 100644
--- a/src/ninep/sources.zig
+++ b/src/ninep/sources.zig
@@ -38,7 +38,7 @@ fn info(n: u64) ?struct { path: []const u8, contents: []const u8, dir: bool } {
/// Stages the children of one archive directory; "" lists the top-level
/// directories the served root shows.
-pub fn stage(p: *Pardes, out: *std.ArrayList(u8), path: []const u8, skip: *u64) void {
+pub fn stage(p: *Pardes, out: *std.ArrayList(u8), path: []const u8, skip: *u64) error{OutOfMemory}!void {
var seen: [sources.len][]const u8 = undefined;
var count: usize = 0;
for (sources, 0..) |source, i| {
@@ -61,7 +61,7 @@ pub fn stage(p: *Pardes, out: *std.ArrayList(u8), path: []const u8, skip: *u64)
continue;
}
const child = archive_node | (@as(u64, i) << 12) | (start + len);
- tree.stageDirent(out, p.gpa, child, len < rest.len, name);
+ try tree.stageDirent(out, p.gpa, child, len < rest.len, name);
}
}
@@ -97,7 +97,7 @@ pub fn handle(p: *Pardes, req: Req) Reply {
if (!found.dir) return Reply.fail(req.tag, E.NOTDIR);
const out = p.fs.stage(p.gpa);
var skip = req.off;
- stage(p, out, found.path, &skip);
+ stage(p, out, found.path, &skip) catch return Reply.fail(req.tag, E.NOMEM);
return .{ .tag = req.tag, .payload = .{ .staged = @intCast(out.items.len) } };
},
.read => {
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index f7ca0cb7..bca89466 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -447,14 +447,14 @@ pub fn resolveSelf(p: *Pardes, path: []const u8) ?u64 {
// ---- staging ----
-pub fn stageDirent(out: *std.ArrayList(u8), gpa: std.mem.Allocator, node: u64, dir: bool, name: []const u8) void {
+pub fn stageDirent(out: *std.ArrayList(u8), gpa: std.mem.Allocator, node: u64, dir: bool, name: []const u8) error{OutOfMemory}!void {
if (name.len == 0 or name.len > 255) return;
var head: [10]u8 = undefined;
std.mem.writeInt(u64, head[0..8], node, .little);
head[8] = @intFromBool(dir);
head[9] = @intCast(name.len);
// Head and name both or neither: a head alone would corrupt the listing.
- out.ensureUnusedCapacity(gpa, head.len + name.len) catch return;
+ try out.ensureUnusedCapacity(gpa, head.len + name.len);
out.appendSliceAssumeCapacity(&head);
out.appendSliceAssumeCapacity(name);
}
@@ -736,20 +736,30 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
fn readdir(p: *Pardes, req: Req, target: Target) Reply {
const out = p.fs.stage(p.gpa);
- var skip = req.off;
+ stageDir(p, out, target, req.off) catch |err| return Reply.fail(req.tag, switch (err) {
+ error.OutOfMemory => E.NOMEM,
+ error.FileNotFound => E.NOENT,
+ error.NotDir => E.NOTDIR,
+ });
+ return .{ .tag = req.tag, .payload = .{ .staged = @intCast(out.items.len) } };
+}
+
+/// The entries of `target` from the `off`th on, staged into `out`.
+fn stageDir(p: *Pardes, out: *std.ArrayList(u8), target: Target, off: u64) error{ OutOfMemory, FileNotFound, NotDir }!void {
+ var skip = off;
switch (target) {
.top => |f| switch (f) {
.root => {
// The guide, then what describes the session, then the
// files that act, then the directories.
inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.dumps, TopFile.addons, TopFile.look, TopFile.exec, TopFile.pager, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.sessions, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.kbdin, TopFile.mousein, TopFile.pane, TopFile.col }) |t| {
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @backingInt(t), t.dir(), t.fileName());
+ if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, @backingInt(t), t.dir(), t.fileName());
}
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, fs.os_root, true, "os");
- sources.stage(p, out, "", &skip);
+ if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, fs.os_root, true, "os");
+ try sources.stage(p, out, "", &skip);
},
.pane => {
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @backingInt(TopFile.new), false, TopFile.new.fileName());
+ if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, @backingInt(TopFile.new), false, TopFile.new.fileName());
var last: u32 = 0;
while (nextSerialAfter(p, last)) |serial| {
last = serial;
@@ -760,7 +770,7 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply {
var buf: [16]u8 = undefined;
// unreachable: a u32 serial fits 16
const name = std.fmt.bufPrint(&buf, "{d}", .{serial}) catch unreachable;
- stageDirent(out, p.gpa, Node.of(serial, .dir), true, name);
+ try stageDirent(out, p.gpa, Node.of(serial, .dir), true, name);
}
},
.col => for (0..p.view().ncol) |c| {
@@ -771,40 +781,39 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply {
var buf: [16]u8 = undefined;
const serial = layout.columnSerial(p, c);
// unreachable: a u32 serial fits 16
- stageDirent(out, p.gpa, Node.ofCol(serial, .dir), true, std.fmt.bufPrint(&buf, "{d}", .{serial}) catch unreachable);
+ try stageDirent(out, p.gpa, Node.ofCol(serial, .dir), true, std.fmt.bufPrint(&buf, "{d}", .{serial}) catch unreachable);
},
- else => return Reply.fail(req.tag, E.NOTDIR),
+ else => return error.NotDir,
},
.col => |c| {
- if (layout.columnBySerial(p, c.serial) == null) return Reply.fail(req.tag, E.NOENT);
- if (c.file != .dir) return Reply.fail(req.tag, E.NOTDIR);
+ if (layout.columnBySerial(p, c.serial) == null) return error.FileNotFound;
+ if (c.file != .dir) return error.NotDir;
inline for (.{ ColFile.tag, ColFile.ctl, ColFile.exec }) |f| {
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, Node.ofCol(c.serial, f), false, f.fileName());
+ if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, Node.ofCol(c.serial, f), false, f.fileName());
}
},
.pane => |t| {
- const id = p.paneBySerial(t.serial) orelse return Reply.fail(req.tag, E.NOENT);
+ const id = p.paneBySerial(t.serial) orelse return error.FileNotFound;
const terminal = p.panes[id].?.isTerminal();
switch (t.file) {
// The pty files are listed inside pty/, and it only on a terminal.
.dir => inline for (comptime std.enums.values(PaneFile)) |f| {
if (comptime f == .dir or (f.inPty() and f != .pty)) continue;
if (f != .pty or terminal) {
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, Node.of(t.serial, f), f.isDir(), f.fileName());
+ if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, Node.of(t.serial, f), f.isDir(), f.fileName());
}
},
.pty => {
- if (!terminal) return Reply.fail(req.tag, E.NOENT);
+ if (!terminal) return error.FileNotFound;
inline for (comptime std.enums.values(PaneFile)) |f| {
if (comptime !f.inPty() or f == .pty) continue;
- if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, Node.of(t.serial, f), false, f.fileName());
+ if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, Node.of(t.serial, f), false, f.fileName());
}
},
- else => return Reply.fail(req.tag, E.NOTDIR),
+ else => return error.NotDir,
}
},
}
- return .{ .tag = req.tag, .payload = .{ .staged = @intCast(out.items.len) } };
}
fn open(p: *Pardes, req: Req, target: Target) Reply {