Skip to content

Commit 63c01a6

Browse files
committed
Avoid compile-time warnings
1 parent 1646ec5 commit 63c01a6

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lib/error_tracker.ex

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,23 @@ defmodule ErrorTracker do
384384
occurrence
385385
end
386386

387+
@default_json_encoder (cond do
388+
Code.ensure_loaded?(JSON) ->
389+
JSON
390+
391+
Code.ensure_loaded?(Jason) ->
392+
Jason
393+
394+
true ->
395+
raise """
396+
No JSON encoder found. Please add Jason to your dependencies:
397+
398+
{:jason, "~> 1.1"}
399+
400+
Or upgrade to Elixir 1.18+.
401+
"""
402+
end)
403+
387404
@doc false
388-
def __default_json_encoder__ do
389-
# Elixir 1.18+ includes the JSON module. On older versions we should fall back to Jason (which
390-
# is listed as an optional dependency).
391-
if Version.match?(System.version(), ">= 1.18.0"),
392-
do: JSON,
393-
else: Jason
394-
end
405+
def __default_json_encoder__, do: @default_json_encoder
395406
end

0 commit comments

Comments
 (0)