From eba47199a51370c9753798fbd2439a85ddc4e5bb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 05:28:09 -0300 Subject: A long err record is cut between words, with an ellipsis An err record's reason was cut at 200 bytes, mid-word. It is now cut at the last word that fits, and ends with an ellipsis. Co-Authored-By: Claude Opus 5.5 --- src/ninep/events.zig | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/ninep/events.zig') diff --git a/src/ninep/events.zig b/src/ninep/events.zig index 105397f3..dd29b207 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -202,7 +202,9 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void { }; } var buf: [256]u8 = undefined; - const record = std.fmt.bufPrint(&buf, "err {s} {s}: {s}\n", .{ serial, file, why[0..@min(why.len, 200)] }) catch return; + // A long reason is cut between words, with an ellipsis, never mid-word. + const kept = pardes.Messages.clip(why, 200); + const record = std.fmt.bufPrint(&buf, "err {s} {s}: {s}{s}\n", .{ serial, file, kept, if (kept.len < why.len) "…" else "" }) catch return; for (record[0 .. record.len - 1]) |*c| if (c.* < ' ') { c.* = ' '; }; @@ -1176,3 +1178,16 @@ test "follow new skips what the log held and waits for what comes after" { try testing.expect(std.mem.endsWith(u8, call(p, .{ .tag = 4, .op = .read, .node = log, .handle = h, .size = 4096 }).bytes, " after it\n")); _ = call(p, .{ .tag = 5, .op = .release, .node = log, .handle = h }); } + +test "a long err record is cut between words, with an ellipsis" { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + _ = wr(p, @intFromEnum(tree.TopFile.ctl), "Bogus " ++ "abcdefgh " ** 40 ++ "\n"); + const log = @intFromEnum(tree.TopFile.log); + const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; + const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes; + const at = std.mem.lastIndexOf(u8, text, "err - ctl: ").?; + const record = text[at .. std.mem.indexOfScalarPos(u8, text, at, '\n').? + 1]; + try testing.expect(std.mem.endsWith(u8, record, "abcdefgh…\n")); + _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h }); +} -- cgit v1.3