From a66a9eb6e0c69cfcb63717bc27704cdc96f382b4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 6 Nov 2026 12:40:11 -0300 Subject: idioms #11, the command layer: exec, builtins, edit_cmd, Messages, Dir, Output, Jump and Pipe say their messages through buffers proven big enough (or the long argument cut) instead of placeholder text, replId takes its 48-byte buffer, a failed Save path, Get or Incl path, Repl send, Tutor, +Unsaved, pipe or Edit output on OOM is reported (reportError) rather than silently dropped, Edit's why and zonWhy cut a long text instead of losing it, and writeFailure names its set Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Messages.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Messages.zig') diff --git a/src/Messages.zig b/src/Messages.zig index ad91cf8d..80e7ab07 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -118,7 +118,7 @@ pub const Message = struct { var text: [8]u8 = "--:--:--".*; if (noTime()) return text; const day: u32 = @intCast(@mod(seconds + gmtoff, 86400)); - _ = std.fmt.bufPrint(&text, "{d:0>2}:{d:0>2}:{d:0>2}", .{ day / 3600, day / 60 % 60, day % 60 }) catch {}; + _ = std.fmt.bufPrint(&text, "{d:0>2}:{d:0>2}:{d:0>2}", .{ day / 3600, day / 60 % 60, day % 60 }) catch unreachable; // under a day: 8 bytes return text; } @@ -435,7 +435,9 @@ pub fn errorWords(err: anyerror, buf: []u8) []const u8 { pub fn zonWhy(diag: *const std.zon.parse.Diagnostics, buf: []u8) []const u8 { if (diag.errors.len == 0) return "not valid ZON"; const first = diag.errors[0]; - return std.fmt.bufPrint(buf, "line {d}: {s}", .{ first.loc.line + 1, first.msg }) catch "not valid ZON"; + var w: std.Io.Writer = .fixed(buf); + w.print("line {d}: {s}", .{ first.loc.line + 1, first.msg }) catch {}; // a long message is cut at the room's end + return w.buffered(); } test "errors are said in words, and a ZON failure names its line" { -- cgit v1.3