Skip to content

Commit

Permalink
Avoid crashing on tupples with jsx
Browse files Browse the repository at this point in the history
jsx:is_term/1 appears to crash when it tries to check upon tuples
  • Loading branch information
ziopio committed May 24, 2024
1 parent e2dbbb1 commit e96e81e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/grisp_connect_log_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jsonify(Event) ->
jsonify_msg(#{msg := {string, String}} = Event) ->
maps:put(msg, unicode:characters_to_binary(String), Event);
jsonify_msg(#{msg := {report, Report}} = Event) ->
case jsx:is_term(Report) of
case is_json_compatible(Report) of
true ->
maps:put(msg, Report, Event);
false ->
Expand Down Expand Up @@ -108,3 +108,9 @@ jsonify_meta(#{meta := Meta} = Event) ->
Optional = maps:without(maps:keys(Default), Meta),
FilterFun = fun(Key, Value) -> jsx:is_term(#{Key => Value}) end,
maps:put(meta, maps:merge(maps:filter(FilterFun, Optional), Default), Event).

is_json_compatible(Term) ->
try jsx:is_term(Term)
catch error:_:_ ->
false
end.

0 comments on commit e96e81e

Please sign in to comment.