diff options
| -rw-r--r-- | sqlite.zig | 12 |
1 files changed, 8 insertions, 4 deletions
| @@ -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 { | |||
| 241 | pub const DetailedError = struct { | 241 | pub 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 | ||
| 246 | fn isThreadSafe() bool { | 250 | fn 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 | ||