From 72d65603eb513d6788a21f02bc211b662c6102e8 Mon Sep 17 00:00:00 2001 From: Hisham Aburaqibah Date: Thu, 6 Nov 2025 09:02:05 +0200 Subject: encoding/json: error handling for custom (un)marshallers --- core/encoding/json/marshal.odin | 4 ++-- core/encoding/json/unmarshal.odin | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin index 81884b71b..58fbbd852 100644 --- a/core/encoding/json/marshal.odin +++ b/core/encoding/json/marshal.odin @@ -62,7 +62,7 @@ Marshal_Options :: struct { mjson_skipped_first_braces_end: bool, } -User_Marshaller :: #type proc(w: io.Writer, v: any) +User_Marshaller :: #type proc(w: io.Writer, v: any) -> Marshal_Error User_Marshaller_Map :: map[typeid]User_Marshaller marshal :: proc(v: any, opt: Marshal_Options = {}, user_marshallers: User_Marshaller_Map = nil, allocator := context.allocator, loc := #caller_location) -> (data: []byte, err: Marshal_Error) { @@ -97,7 +97,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options, user_mars if user_marshallers != nil { marshaller := user_marshallers[v.id] if marshaller != nil { - marshaller(w, v) + marshaller(w, v) or_return return } } diff --git a/core/encoding/json/unmarshal.odin b/core/encoding/json/unmarshal.odin index c1a2725a4..564b84842 100644 --- a/core/encoding/json/unmarshal.odin +++ b/core/encoding/json/unmarshal.odin @@ -26,7 +26,7 @@ Unmarshal_Error :: union { Unsupported_Type_Error, } -User_Unmarshaller :: #type proc(p: ^Parser, v: any) +User_Unmarshaller :: #type proc(p: ^Parser, v: any) -> Unmarshal_Error User_Unmarshaller_Map :: map[typeid]User_Unmarshaller unmarshal_any :: proc(data: []byte, v: any, spec := DEFAULT_SPECIFICATION, user_unmarshallers: User_Unmarshaller_Map, allocator := context.allocator) -> Unmarshal_Error { @@ -277,7 +277,7 @@ unmarshal_value :: proc(p: ^Parser, v: any, user_unmarshallers: User_Unmarshalle if user_unmarshallers != nil { unmarshaller := user_unmarshallers[v.id] if unmarshaller != nil { - unmarshaller(p, v) + unmarshaller(p, v) or_return return } } -- cgit v1.2.3