From 73e7ceac8ac22448e40b7a80f2cafe130e88c9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20G=C3=B6m=C3=B6ri?= Date: Fri, 26 Nov 2021 13:08:47 +0100 Subject: [PATCH] Ensure parser always returns `erl_anno:location()` in errors --- src/erlfmt_parse.yrl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/erlfmt_parse.yrl b/src/erlfmt_parse.yrl index fe8d58c5..3ae8398d 100644 --- a/src/erlfmt_parse.yrl +++ b/src/erlfmt_parse.yrl @@ -1049,13 +1049,19 @@ parse_node(Tokens) -> case parse(Tokens) of {ok, _} = Res -> Res; - Error -> + {error, {AnnoOrLoc, Mod, Description}} -> case parse([{standalone_exprs, element(2, hd(Tokens))} | Tokens]) of {ok, _} = Res -> Res; - _ -> Error + _ -> {error, {error_location(AnnoOrLoc), Mod, Description}} end end. +-spec error_location(erlfmt_scan:anno() | erl_anno:location()) -> erl_anno:location(). +error_location(#{location := Loc}) -> + Loc; +error_location(Loc) -> + Loc. + %% unwrap single-expr definitions, wrapped in guards by the parser build_macro_def( {'-', Anno},