summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/look.zig8
-rw-r--r--src/ninep/ctl.zig17
2 files changed, 23 insertions, 2 deletions
diff --git a/src/look.zig b/src/look.zig
index 4e948fad..09e371b2 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -1540,8 +1540,12 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void {
if (comptime pdf_enabled) if (target.kind == .pdf) {
if (focusPaneByPath(p, target.path, target.at)) return;
const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots);
- _ = panes.Pdf.openPane(p, free, target.path, target.at.line) catch |err|
- return p.reportError(id, "look", err);
+ // Said with its path and why, as an image that cannot be read is.
+ _ = panes.Pdf.openPane(p, free, target.path, target.at.line) catch |err| {
+ var said: [miss_path_cap + 64]u8 = undefined;
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ return p.reportError(id, std.fmt.bufPrint(&said, "look: {s}: not a PDF pardes can read", .{missText(target.path, &cut)}) catch "look: not a PDF pardes can read", err);
+ };
exec.placeNew(p, id, id, free, .doc);
return;
};
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index ebb85609..a11bfeda 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -2140,6 +2140,23 @@ test "a corrupt image fails its look with an err, and no pane is made" {
try testing.expectEqual(count, after);
}
+test "a truncated PDF fails its look with its path and why" {
+ if (comptime !pardes.pdf_enabled) return;
+ const p = try withFile(testing.allocator, "x\n");
+ defer p.deinit();
+ var tmp = testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const bytes = try @import("mupdf").makeLinksTestPdf(testing.allocator);
+ defer testing.allocator.free(bytes);
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "cut.pdf", .data = bytes[0..40] });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
+ var line: [4200]u8 = undefined;
+ const r = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/cut.pdf\n", .{dir}));
+ try testing.expectEqual(Status.err, r.reply.status);
+ try testing.expect(std.mem.indexOf(u8, r.reply.ename, "cut.pdf: not a PDF pardes can read: ") != null);
+}
+
test "a PDF's body reads its page's text layer, and takes no write" {
if (comptime !pardes.pdf_enabled) return;
const p = try withFile(testing.allocator, "x\n");