summaryrefslogtreecommitdiff
path: root/sqlite.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2021-04-17 19:12:08 +0200
committerGravatar Vincent Rischmann2021-04-17 19:12:30 +0200
commit6e026ca87d9889022ca1d8d66e5bfe57624b46c0 (patch)
treed5e64ee174a3fb42c1f6004be98ca600f7903167 /sqlite.zig
parentmake use_bundled work for all targets (diff)
downloadzig-sqlite-6e026ca87d9889022ca1d8d66e5bfe57624b46c0.tar.gz
zig-sqlite-6e026ca87d9889022ca1d8d66e5bfe57624b46c0.tar.xz
zig-sqlite-6e026ca87d9889022ca1d8d66e5bfe57624b46c0.zip
fix DetailedError and Diagnostics formatting
Diffstat (limited to 'sqlite.zig')
-rw-r--r--sqlite.zig12
1 files changed, 8 insertions, 4 deletions
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 {
200 pub fn format(self: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { 200 pub fn format(self: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
201 if (self.err) |err| { 201 if (self.err) |err| {
202 if (self.message.len > 0) { 202 if (self.message.len > 0) {
203 _ = try writer.print("{{message: {s}, error: {s}}}", .{ self.message, err.message }); 203 _ = try writer.print("{{message: {s}, detailed error: {}}}", .{ self.message, err });
204 return; 204 return;
205 } 205 }
206 206
207 _ = try writer.write(err.message); 207 _ = try err.format(fmt, options, writer);
208 return; 208 return;
209 } 209 }
210 210
@@ -241,6 +241,10 @@ pub const InitOptions = struct {
241pub const DetailedError = struct { 241pub const DetailedError = struct {
242 code: usize, 242 code: usize,
243 message: []const u8, 243 message: []const u8,
244
245 pub fn format(self: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
246 _ = try writer.print("{{code: {}, message: {s}}}", .{ self.code, self.message });
247 }
244}; 248};
245 249
246fn isThreadSafe() bool { 250fn isThreadSafe() bool {
@@ -1903,7 +1907,7 @@ test "sqlite: diagnostics format" {
1903 .message = "barbaz", 1907 .message = "barbaz",
1904 }, 1908 },
1905 }, 1909 },
1906 .exp = "my diagnostics: barbaz", 1910 .exp = "my diagnostics: {code: 20, message: barbaz}",
1907 }, 1911 },
1908 .{ 1912 .{
1909 .input = .{ 1913 .input = .{
@@ -1913,7 +1917,7 @@ test "sqlite: diagnostics format" {
1913 .message = "barbaz", 1917 .message = "barbaz",
1914 }, 1918 },
1915 }, 1919 },
1916 .exp = "my diagnostics: {message: foobar, error: barbaz}", 1920 .exp = "my diagnostics: {message: foobar, detailed error: {code: 20, message: barbaz}}",
1917 }, 1921 },
1918 }; 1922 };
1919 1923