summaryrefslogtreecommitdiff
path: root/src/colors.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-01 05:04:57 -0300
committerGabriel Schneider <[email protected]>2026-10-01 05:18:09 -0300
commit51ddaaf3917ad7968df877d10580d1eadb926688 (patch)
treebedad9f6f2c1b04a34c76599ed126fc61b2b5ac9 /src/colors.zig
parent250db41743f77ce3d8421f729bdea0065aa6bc79 (diff)
downloadpardes-51ddaaf3917ad7968df877d10580d1eadb926688.tar.gz
pardes-51ddaaf3917ad7968df877d10580d1eadb926688.zip
Restore and ThemeFile failures say why in words, a ZON one with its line: never FileTooLarge, ParseZon or a bare `parse zon`
Restore read failures named the Zig error (FileTooLarge, NotAFile, ReadFailed), a file that is no dump said `not a pardes dump (ParseZon)`, and a ThemeFile that did not parse said `parse zon`. Messages.errorWords says an error in words (the few that read badly spelled out plainly, the rest spaced and lower case, as reportError did), and zonWhy gives the parser's first error with its line: `not a pardes dump: line 1: expected ...`, `theme file x.zon: line 3: ...`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/colors.zig')
-rw-r--r--src/colors.zig18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/colors.zig b/src/colors.zig
index d04c009e..a45184c8 100644
--- a/src/colors.zig
+++ b/src/colors.zig
@@ -766,10 +766,15 @@ pub fn failThemeFile(p: *Pardes, generation: u32, err: anyerror) void {
/// A theme file's failure, said with its path: `theme file x.zon: file
/// not found`, not which file left to guess.
fn themeFileError(p: *Pardes, request: ThemeFileRequest, err: anyerror) void {
- var said: [300]u8 = undefined;
+ var words: [128]u8 = undefined;
+ themeFileFailure(p, request, pardes.Messages.errorWords(err, &words));
+}
+
+fn themeFileFailure(p: *Pardes, request: ThemeFileRequest, why: []const u8) void {
+ var said: [520]u8 = undefined;
var cut: [200]u8 = undefined;
const path = @import("ninep/tree.zig").fitErr(request.path, &cut);
- p.reportError(request.pane, std.fmt.bufPrint(&said, "theme file {s}", .{path}) catch "theme file", err);
+ p.reportFailure(request.pane, std.fmt.bufPrint(&said, "theme file {s}: {s}", .{ path, why }) catch "theme file: not loaded");
revertThemeFile(p);
}
@@ -802,7 +807,11 @@ pub fn loadThemeFile(p: *Pardes, generation: u32, bytes: []const u8, animate: bo
var diagnostics: std.zon.parse.Diagnostics = .{};
defer diagnostics.deinit(p.gpa);
const parsed = std.zon.parse.fromSliceAlloc(Theme, p.gpa, source, &diagnostics, .{}) catch |err| {
- themeFileError(p, request, err);
+ if (err != error.ParseZon) themeFileError(p, request, err) else {
+ // Which line, and what the parser wanted there.
+ var why: [200]u8 = undefined;
+ themeFileFailure(p, request, pardes.Messages.zonWhy(&diagnostics, &why));
+ }
return false;
};
if (parsed.name.len == 0 or parsed.name.len > 255) {
@@ -983,6 +992,9 @@ test "ThemeFile parses ZON atomically and Theme returns to the compiled ring" {
// A half-written save is rejected without disturbing the last good value.
try std.testing.expect(!loadThemeFile(p, request_effect.generation, ".{ .name = ", true));
+ // Said with its line, in words: never a bare `parse zon`.
+ const said = p.panes[0].?.msg[0..p.panes[0].?.msg_len];
+ try std.testing.expect(std.mem.indexOf(u8, said, ": line 1: ") != null and std.mem.indexOf(u8, said, "parse zon") == null);
try std.testing.expectEqualStrings("mine", p.theme().name);
try std.testing.expectEqual(@as(?[3]u8, .{ 1, 2, 3 }), p.theme().bg);