aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2024-05-23 19:44:07 +0100
committerLouis Pilfold <louis@lpil.uk>2024-05-23 19:44:07 +0100
commite89b5c38724ebf685cd023b3e83f8e1e2d18bde4 (patch)
treeb36b51f4646bdd3e943a622360bcb811c9c3ae2d
parent549ecb851a150a494b72fad172e91f3f4b24653b (diff)
downloadgleam_json-e89b5c38724ebf685cd023b3e83f8e1e2d18bde4.tar.gz
gleam_json-e89b5c38724ebf685cd023b3e83f8e1e2d18bde4.zip
Helpful error message for lower Erlang/OTP versions
-rw-r--r--src/gleam_json_ffi.erl23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/gleam_json_ffi.erl b/src/gleam_json_ffi.erl
index 888ae51..c81adf9 100644
--- a/src/gleam_json_ffi.erl
+++ b/src/gleam_json_ffi.erl
@@ -5,6 +5,27 @@
bool/1, null/0, array/1, object/1
]).
+-if(?OTP_RELEASE < 27).
+-define(bad_version,
+ error({erlang_otp_27_required, << "Insufficient Erlang/OTP version.
+
+`gleam_json` uses the Erlang `json` module introduced in Erlang/OTP 27.
+You are using Erlang/OTP"/utf8, (integer_to_binary(?OTP_RELEASE))/binary, "
+Please upgrade your Erlang install or downgrade to `gleam_json` v1.0.1.
+"/utf8>>})).
+
+decode(_) -> ?bad_version.
+json_to_iodata(_) -> ?bad_version.
+json_to_string(_) -> ?bad_version.
+int(_) -> ?bad_version.
+float(_) -> ?bad_version.
+string(_) -> ?bad_version.
+bool(_) -> ?bad_version.
+array(_) -> ?bad_version.
+object(_) -> ?bad_version.
+null() -> ?bad_version.
+-else.
+
decode(Json) ->
try
{ok, json:decode(Json)}
@@ -41,3 +62,5 @@ array_loop([Elem | Rest]) -> [$,, Elem | array_loop(Rest)].
object(List) -> encode_object([[$,, string(Key), $: | Value] || {Key, Value} <- List]).
encode_object([]) -> <<"{}">>;
encode_object([[_Comma | Entry] | Rest]) -> ["{", Entry, Rest, "}"].
+
+-endif.