Skip to content

Commit

Permalink
Merge branch 'master' into serializable-options
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwencool authored Jun 10, 2023
2 parents fa9868f + bd46e34 commit 5988ee6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
27 changes: 9 additions & 18 deletions src/hocon_token.erl
Original file line number Diff line number Diff line change
Expand Up @@ -289,25 +289,16 @@ parse_error(Line, ErrorInfo, Ctx) ->
throw({parse_error, format_error(Line, ErrorInfo, Ctx)}).

format_error(Line, ErrorInfo, #{filename := [undefined]}) ->
unicode_bin(
[
ErrorInfo,
io_lib:format(
" line_number ~w",
[Line]
)
]
);
#{
reason => lists:flatten([ErrorInfo]),
line => Line
};
format_error(Line, ErrorInfo, Ctx) ->
unicode_bin(
[
ErrorInfo,
io_lib:format(
" line_number ~w in_file ~s",
[Line, hd(hocon_util:get_stack(filename, Ctx))]
)
]
).
#{
reason => lists:flatten([ErrorInfo]),
line => Line,
file => hd(hocon_util:get_stack(filename, Ctx))
}.

unicode_bin(L) -> unicode:characters_to_binary(L, utf8).
unicode_list(B) -> unicode:characters_to_list(B, utf8).
4 changes: 2 additions & 2 deletions test/hocon_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ concat_error_binary_test_() ->
].

parse_sytax_error_test() ->
{error, {parse_error, Txt}} = hocon:binary("a=xyz, b=true${a}"),
?assertEqual(Txt, <<"syntax error before: <<\"a\">> line_number 1">>).
{error, {parse_error, Error}} = hocon:binary("a=xyz, b=true${a}"),
?assertEqual(Error, #{line => 1, reason => "syntax error before: <<\"a\">>"}).

concat_error_file_test_() ->
[
Expand Down

0 comments on commit 5988ee6

Please sign in to comment.