Skip to content

Commit c9d0294

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

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/error_tracker.ex

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

387+
@default_json_encoder (cond do
388+
Code.ensure_loaded?(JSON) -> JSON
389+
Code.ensure_loaded?(Jason) -> Jason
390+
true ->
391+
raise """
392+
No JSON encoder found. Please add Jason to your dependencies:
393+
394+
{:jason, "~> 1.1"}
395+
396+
Or upgrade to Elixir 1.18+.
397+
"""
398+
end)
399+
387400
@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
401+
def __default_json_encoder__, do: @default_json_encoder
395402
end

0 commit comments

Comments
 (0)