From 6e026ca87d9889022ca1d8d66e5bfe57624b46c0 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sat, 17 Apr 2021 19:12:08 +0200 Subject: fix DetailedError and Diagnostics formatting --- sqlite.zig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index efdcfb9..b0576ec 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -200,11 +200,11 @@ pub const Diagnostics = struct { pub fn format(self: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { if (self.err) |err| { if (self.message.len > 0) { - _ = try writer.print("{{message: {s}, error: {s}}}", .{ self.message, err.message }); + _ = try writer.print("{{message: {s}, detailed error: {}}}", .{ self.message, err }); return; } - _ = try writer.write(err.message); + _ = try err.format(fmt, options, writer); return; } @@ -241,6 +241,10 @@ pub const InitOptions = struct { pub const DetailedError = struct { code: usize, message: []const u8, + + pub fn format(self: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { + _ = try writer.print("{{code: {}, message: {s}}}", .{ self.code, self.message }); + } }; fn isThreadSafe() bool { @@ -1903,7 +1907,7 @@ test "sqlite: diagnostics format" { .message = "barbaz", }, }, - .exp = "my diagnostics: barbaz", + .exp = "my diagnostics: {code: 20, message: barbaz}", }, .{ .input = .{ @@ -1913,7 +1917,7 @@ test "sqlite: diagnostics format" { .message = "barbaz", }, }, - .exp = "my diagnostics: {message: foobar, error: barbaz}", + .exp = "my diagnostics: {message: foobar, detailed error: {code: 20, message: barbaz}}", }, }; -- cgit v1.2.3