summaryrefslogtreecommitdiff
path: root/src/ninep/events.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 13:16:39 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commit961bea06443e25a92e02be58136065c2a1ea84c1 (patch)
tree983433b6ec9b5855530e187ccc2e8a783b8fd42e /src/ninep/events.zig
parent80f4398f1fed8d46d73cab8045005c02189b34fc (diff)
downloadpardes-961bea06443e25a92e02be58136065c2a1ea84c1.tar.gz
pardes-961bea06443e25a92e02be58136065c2a1ea84c1.zip
idioms #15, the catch unreachable sites slice b added, re-classified: 29 that a word, a path, an id or a function's text could reach go back to a cut through Kind.Buf (or, at echoCommand's and Repl's writers, a failure handled once at the writer), 95 stay because every argument is an integer, a literal, a comptime word or a cut in the same statement (one added to Ask's arg, ctl's why, choices, word and the ids and fields paneText writes, events' records and Edit's names), each with its reason on its line
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/ninep/events.zig')
-rw-r--r--src/ninep/events.zig15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index a25b97b2..be0c4141 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -174,7 +174,7 @@ pub fn noteLogAs(p: *Pardes, kind: LogKind, pane: *Pane, path: []const u8) void
var name_buf: [4 * 4096]u8 = undefined;
// As /index shows it: a newline in the name is `\n`.
const name = shown(path, &name_buf);
- pushLog(p, std.fmt.bufPrint(&buf, "{s} {d} {s}\n", .{ @tagName(kind), pane.serial, name }) catch unreachable); // name is at most name_buf's
+ pushLog(p, std.fmt.bufPrint(&buf, "{s} {d} {s}\n", .{ @tagName(kind), pane.serial, name[0..@min(name.len, name_buf.len)] }) catch unreachable); // an enum's name, a u32 and name_buf's 4 * 4096 fit 64 more
}
/// Records `msg <serial> <text>` for what the editor said, `-` for no pane.
@@ -189,9 +189,9 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void {
const cut = if (kept.len < said.len) "…" else "";
bootFirst(p);
pushCounting(p, (if (serial == 0)
- std.fmt.bufPrint(&buf, "msg - {s}{s}\n", .{ kept, cut })
+ std.fmt.bufPrint(&buf, "msg - {s}{s}\n", .{ kept[0..@min(kept.len, pardes.Messages.LoggedMessage.cap)], cut })
else
- std.fmt.bufPrint(&buf, "msg {d} {s}{s}\n", .{ serial, kept, cut })) catch unreachable, said); // kept is at most cap
+ std.fmt.bufPrint(&buf, "msg {d} {s}{s}\n", .{ serial, kept[0..@min(kept.len, pardes.Messages.LoggedMessage.cap)], cut })) catch unreachable, said); // a u32, cap and 9 fit cap + 32
}
/// `notePath` for an `err` record: the same one again straight after is
@@ -199,7 +199,7 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void {
pub fn noteErrCounted(p: *Pardes, text: []const u8) void {
bootFirst(p);
var buf: [pardes.memory.limits.host_path_cap + 16]u8 = undefined;
- pushCounting(p, std.fmt.bufPrint(&buf, "err {s}\n", .{text[0..@min(text.len, buf.len - 16)]}) catch unreachable, text);
+ pushCounting(p, std.fmt.bufPrint(&buf, "err {s}\n", .{text[0..@min(text.len, buf.len - 16)]}) catch unreachable, text); // buf.len - 16 and 5 fit buf.len
}
/// Records `<what> <path>`: `dump <path>` when a Dump is written,
@@ -207,8 +207,7 @@ pub fn noteErrCounted(p: *Pardes, text: []const u8) void {
pub fn notePath(p: *Pardes, what: []const u8, path: []const u8) void {
bootFirst(p);
var buf: [pardes.memory.limits.host_path_cap + 16]u8 = undefined;
- // unreachable: a record's word is a short literal, and the path is cut to fit.
- pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what, path[0..@min(path.len, buf.len - 16)] }) catch unreachable);
+ pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what[0..@min(what.len, 14)], path[0..@min(path.len, buf.len - 16)] }) catch unreachable); // 14, buf.len - 16 and 2 fit buf.len
}
/// Records `err <serial|-> <file>: <why>` for a write that was refused or
@@ -250,13 +249,13 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void {
},
};
}
- var buf: [256]u8 = undefined;
+ var buf: [288]u8 = undefined;
// A reason that names its file already (`look: no space...` from a
// look) is not prefixed twice: `err 3 look: no space...`.
const reason = if (why.len > file.len + 2 and std.ascii.startsWithIgnoreCase(why, file) and std.mem.startsWith(u8, why[file.len..], ": ")) why[file.len + 2 ..] else why;
// A long reason is cut between words, with an ellipsis, never mid-word.
const kept = pardes.Messages.clip(reason, 200);
- const record = std.fmt.bufPrint(&buf, "err {s} {s}: {s}{s}\n", .{ serial, file, kept, if (kept.len < reason.len) "…" else "" }) catch unreachable; // 10 + 32 + 200 + 11 fit 256
+ const record = std.fmt.bufPrint(&buf, "err {s} {s}: {s}{s}\n", .{ serial[0..@min(serial.len, 32)], file[0..@min(file.len, 32)], kept[0..@min(kept.len, 200)], if (kept.len < reason.len) "…" else "" }) catch unreachable; // 32 + 32 + 200 + 11 fit 288
for (record[0 .. record.len - 1]) |*c| if (c.* < ' ') {
c.* = ' ';
};