From 9dc93a8d31f08f5aec81e7c076220b598db37cbb Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 30 Sep 2026 23:12:58 -0300 Subject: A look at a file it may not read says which: "look: : permission denied" The refusal said "look: permission denied", leaving the script to guess which of the paths it looked at was locked. A file or image that will not open is now named in the failure, its path cut in the middle when long. Co-Authored-By: Claude Opus 5.5 --- src/look.zig | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/look.zig') diff --git a/src/look.zig b/src/look.zig index 238e479f..922504c0 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1238,6 +1238,15 @@ test "a miss names a long path by its start and its end, its middle given up to try std.testing.expectEqualStrings("short/path.txt", missText("short/path.txt", &cut)); } +/// A file that is there but would not open: said with its path, `look: +/// : permission denied`, the path cut in its middle when long. +fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void { + if (@import("Messages.zig").dialReason(err) != null) return p.reportError(id, path, err); + var cut: [miss_path_cap + "…".len]u8 = undefined; + var said: [miss_path_cap + 16]u8 = undefined; + p.reportError(id, std.fmt.bufPrint(&said, "look: {s}", .{missText(path, &cut)}) catch "look", err); +} + fn missedPage(p: *Pardes, id: usize, path: []const u8, page: usize) void { var cut: [miss_path_cap + "…".len]u8 = undefined; missed(p, id, "{s} has no page {d}", .{ missText(path, &cut), page }); @@ -1761,7 +1770,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { if (!focusPaneByPath(p, target.path, target.at)) { const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| - return p.reportError(id, if (@import("Messages.zig").dialReason(err) != null) target.path else "look", err); + return lookOpenFailed(p, id, target.path, err); if (target.at.col > 0) nt.body.cur_col = @intCast(target.at.col - 1); const failures = p.fs.failures; exec.placeNew(p, id, id, free, .doc); @@ -1783,7 +1792,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { if (focusPaneByPath(p, target.path, .{})) return; const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); const made = panes.Image.create(p, free, target.path, &.{}) catch |err| - return p.reportError(id, if (@import("Messages.zig").dialReason(err) != null) target.path else "look", err); + return lookOpenFailed(p, id, target.path, err); // One it cannot read (corrupt, truncated, not what its name says) // is said, a failure, rather than shown as a blank pane. if (!@import("image.zig").readable(made.image.?.raw)) { -- cgit v1.3