aboutsummaryrefslogtreecommitdiff
path: root/src/gleam_stdlib.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gleam_stdlib.erl')
-rw-r--r--src/gleam_stdlib.erl9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index c757857..e9d6391 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -49,8 +49,10 @@ iodata_append(Iodata, String) -> [Iodata, String].
identity(X) -> X.
-decode_error_msg(Expected, Data) ->
- {error, [{decode_error, Expected, classify_dynamic(Data), []}]}.
+decode_error_msg(Expected, Data) when is_binary(Expected) ->
+ decode_error(Expected, classify_dynamic(Data)).
+decode_error(Expected, Got) when is_binary(Expected) andalso is_binary(Got) ->
+ {error, [{decode_error, Expected, Got, []}]}.
classify_dynamic(X) when is_atom(X) -> <<"Atom">>;
classify_dynamic(X) when is_binary(X) -> <<"String">>;
@@ -94,7 +96,8 @@ decode_list(Data) -> decode_error_msg(<<"List">>, Data).
decode_field(Data, Key) ->
case Data of
#{Key := Value} -> {ok, Value};
- _ -> decode_error_msg("object", Data)
+ _ ->
+ decode_error(<<"field"/utf8>>, <<"nothing"/utf8>>)
end.
size_of_tuple(Data) -> tuple_size(Data).