summaryrefslogtreecommitdiff
path: root/src/Messages.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Messages.zig')
-rw-r--r--src/Messages.zig16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/Messages.zig b/src/Messages.zig
index 2314939f..6d064c93 100644
--- a/src/Messages.zig
+++ b/src/Messages.zig
@@ -519,20 +519,20 @@ pub fn errorWords(err: anyerror, buf: []u8) []const u8 {
/// A ZON parse failure in a person's words: the first error the parser
/// found and its line, `line 3: expected ','`.
pub fn zonWhy(diag: *const std.zon.parse.Diagnostics, buf: []u8) []const u8 {
- var errors = diag.iterateErrors();
- const first = errors.next() orelse return "not valid ZON";
- const loc = first.getLocation(diag);
- return std.fmt.bufPrint(buf, "line {d}: {f}", .{ loc.line + 1, first.fmtMessage(diag) }) catch "not valid ZON";
+ 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";
}
test "errors are said in words, and a ZON failure names its line" {
var buf: [128]u8 = undefined;
try std.testing.expectEqualStrings("file not found", errorWords(error.FileNotFound, &buf));
try std.testing.expectEqualStrings("too large", errorWords(error.FileTooLarge, &buf));
- var diag: std.zon.parse.Diagnostics = .{};
- defer diag.deinit(std.testing.allocator);
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ var diag: std.zon.parse.Diagnostics = undefined;
const T = struct { a: u8 };
- try std.testing.expectError(error.ParseZon, std.zon.parse.fromSliceAlloc(T, std.testing.allocator, ".{\n .a = 1,\n .b = 2 }", &diag, .{}));
+ try std.testing.expectError(error.ParseZon, std.zon.parse.fromSlice(T, .{ .gpa = std.testing.allocator, .arena = arena.allocator(), .source = ".{\n .a = 1,\n .b = 2 }", .diagnostics = &diag }));
try std.testing.expect(std.mem.startsWith(u8, zonWhy(&diag, &buf), "line 3: "));
}
@@ -721,7 +721,7 @@ test "with no frontend attached a message goes once it has lingered, on the cloc
// line above it with it.
p.unattended = true;
// A read served meanwhile changes nothing; the session's loop expires.
- _ = p.serveFs(.{ .tag = 1, .op = .read, .node = @intFromEnum(ctlfs.TopFile.index), .size = 64 });
+ _ = p.serveFs(.{ .tag = 1, .op = .read, .node = @backingInt(ctlfs.TopFile.index), .size = 64 });
try std.testing.expect(pane.msg_len > 0);
expireUnattended(p);
try std.testing.expectEqual(@as(u16, 0), pane.msg_len);