From e96e81e43302c19d921666b99805b244b7af3d3b Mon Sep 17 00:00:00 2001 From: Luca Succi Date: Fri, 24 May 2024 18:09:13 +0200 Subject: [PATCH] Avoid crashing on tupples with jsx jsx:is_term/1 appears to crash when it tries to check upon tuples --- src/grisp_connect_log_server.erl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/grisp_connect_log_server.erl b/src/grisp_connect_log_server.erl index 0bf87be..fe07d3c 100644 --- a/src/grisp_connect_log_server.erl +++ b/src/grisp_connect_log_server.erl @@ -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 -> @@ -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.