| ... | @@ -2268,7 +2268,7 @@ pub fn stringify( | ... | @@ -2268,7 +2268,7 @@ pub fn stringify( |
| 2268 | value: anytype, | 2268 | value: anytype, |
| 2269 | options: StringifyOptions, | 2269 | options: StringifyOptions, |
| 2270 | out_stream: anytype, | 2270 | out_stream: anytype, |
| 2271 | ) @TypeOf(out_stream).Error!void { | 2271 | ) !void { |
| 2272 | const T = @TypeOf(value); | 2272 | const T = @TypeOf(value); |
| 2273 | switch (@typeInfo(T)) { | 2273 | switch (@typeInfo(T)) { |
| 2274 | .Float, .ComptimeFloat => { | 2274 | .Float, .ComptimeFloat => { |
| ... | @@ -2767,3 +2767,20 @@ test "deserializing string with escape sequence into sentinel slice" { | ... | @@ -2767,3 +2767,20 @@ test "deserializing string with escape sequence into sentinel slice" { |
| 2767 | // Double-check that we're getting the right result | 2767 | // Double-check that we're getting the right result |
| 2768 | try testing.expect(mem.eql(u8, result, "\n")); | 2768 | try testing.expect(mem.eql(u8, result, "\n")); |
| 2769 | } | 2769 | } |
| | 2770 | |
| | 2771 | test "stringify struct with custom stringify that returns a custom error" { |
| | 2772 | var ret = std.json.stringify(struct { |
| | 2773 | field: Field = .{}, |
| | 2774 | |
| | 2775 | pub const Field = struct { |
| | 2776 | field: ?[]*Field = null, |
| | 2777 | |
| | 2778 | const Self = @This(); |
| | 2779 | pub fn jsonStringify(_: Self, _: StringifyOptions, _: anytype) error{CustomError}!void { |
| | 2780 | return error.CustomError; |
| | 2781 | } |
| | 2782 | }; |
| | 2783 | }{}, StringifyOptions{}, std.io.null_writer); |
| | 2784 | |
| | 2785 | try std.testing.expectError(error.CustomError, ret); |
| | 2786 | } |