summaryrefslogtreecommitdiff
path: root/src/Messages.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 12:40:11 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commita66a9eb6e0c69cfcb63717bc27704cdc96f382b4 (patch)
tree400e3034a6c71c1d15d0ad302e1293a4290071b9 /src/Messages.zig
parent36a51ddc67d0beb7d9851fb2425cf780a47fed36 (diff)
downloadpardes-a66a9eb6e0c69cfcb63717bc27704cdc96f382b4.tar.gz
pardes-a66a9eb6e0c69cfcb63717bc27704cdc96f382b4.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/Messages.zig')
-rw-r--r--src/Messages.zig6
1 files changed, 4 insertions, 2 deletions
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" {