From bfc6839d39fe26dea1f2e230531f73a8ad95c114 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Thu, 11 Apr 2024 14:39:08 +0000 Subject: [PATCH 1/2] Turn rich compiler errors on by default --- apps/rebar/src/rebar.hrl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/rebar/src/rebar.hrl b/apps/rebar/src/rebar.hrl index 6d601c740..a402d2861 100644 --- a/apps/rebar/src/rebar.hrl +++ b/apps/rebar/src/rebar.hrl @@ -28,7 +28,7 @@ -define(DEFAULT_CDN, "https://repo.hex.pm"). -define(LOCK_FILE, "rebar.lock"). -define(DEFAULT_COMPILER_SOURCE_FORMAT, relative). --define(DEFAULT_COMPILER_ERROR_FORMAT, minimal). % 'rich' for multiline values +-define(DEFAULT_COMPILER_ERROR_FORMAT, rich). % 'minimal' for default values as of 3.23.0 and earlier -define(PACKAGE_INDEX_VERSION, 6). -define(PACKAGE_TABLE, package_index). -define(INDEX_FILE, "packages.idx"). From 720817292cf8b060e78516a213b6e126fbbf56e4 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Tue, 16 Apr 2024 18:40:42 +0000 Subject: [PATCH 2/2] preserve tabs in rich compiler output --- apps/rebar/src/rebar_compiler_format.erl | 6 +++++- apps/rebar/test/rebar_compiler_format_SUITE.erl | 12 ++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/rebar/src/rebar_compiler_format.erl b/apps/rebar/src/rebar_compiler_format.erl index a8992a67b..f27d5f64a 100644 --- a/apps/rebar/src/rebar_compiler_format.erl +++ b/apps/rebar/src/rebar_compiler_format.erl @@ -23,7 +23,7 @@ format(Source, {Line, Column}, Extra, Desc, Config) -> [LnPad, Source, LnPad, Line, colorize(LnBin, Column), - LnPad, lists:duplicate(max(0, Column-1), " "), Arrow, Extra, Desc]); + LnPad, indent(max(0, Column-1), LnBin), Arrow, Extra, Desc]); _ -> ?FMT("~ts:~w:~w: ~ts~ts~n", [Source, Line, Column, Extra, Desc]) end. @@ -37,6 +37,10 @@ find_line(Nth, Source) -> error:X -> {error, X} end. +indent(0, _) -> ""; +indent(N, <<"\t", Rest/binary>>) -> [$\t | indent(N-1, Rest)]; +indent(N, <<_/utf8, Rest/binary>>) -> [$\s | indent(N-1, Rest)]. + compiler_error_format(Opts) -> %% `Opts' can be passed in both as a list or a dictionary depending %% on whether the first call to rebar_erlc_compiler was done with diff --git a/apps/rebar/test/rebar_compiler_format_SUITE.erl b/apps/rebar/test/rebar_compiler_format_SUITE.erl index e35f5b888..1a7d297f9 100644 --- a/apps/rebar/test/rebar_compiler_format_SUITE.erl +++ b/apps/rebar/test/rebar_compiler_format_SUITE.erl @@ -37,7 +37,7 @@ oracle() -> ++ lists:duplicate(9, $\n) ++ "first character on line 11.\n" ++ lists:duplicate(99, $\n) ++ - "case X of ^whatever % on line 111\n". + "case \tX of ^whatever % on line 111\n". minimal() -> [{doc, "showing minimal (default) output"}]. @@ -48,8 +48,8 @@ minimal(Config) -> rebar_compiler_format:format(Path, {1,20}, "=> ", "unexpected token: ;", Conf)), ?assertEqual(Path++":11:1: some message"++?EOL, rebar_compiler_format:format(Path, {11,1}, "", "some message", Conf)), - ?assertEqual(Path++":111:11: the character '^' is not expected here."++?EOL, - rebar_compiler_format:format(Path, {111,11}, "", "the character '^' is not expected here.", Conf)), + ?assertEqual(Path++":111:12: the character '^' is not expected here."++?EOL, + rebar_compiler_format:format(Path, {111,12}, "", "the character '^' is not expected here.", Conf)), ?assertEqual(Path++":-23:-42: invalid ranges."++?EOL, rebar_compiler_format:format(Path, {-23,-42}, "", "invalid ranges.", Conf)), ?assertEqual(Path++":-23:-42: invalid ranges."++?EOL, @@ -78,9 +78,9 @@ nocolor(Config) -> rebar_compiler_format:format(Path, {11,1}, "", "some message", Conf)), ?assertEqual(" ┌─ "++Path++":"++?EOL++ " │"++?EOL++ - " 111 │ case X of ^whatever % on line 111"++?EOL++ - " │ ╰── the character '^' is not expected here."++?EOL++?EOL, - rebar_compiler_format:format(Path, {111,11}, "", "the character '^' is not expected here.", Conf)), + " 111 │ case \tX of ^whatever % on line 111"++?EOL++ + " │ \t ╰── the character '^' is not expected here."++?EOL++?EOL, + rebar_compiler_format:format(Path, {111,12}, "", "the character '^' is not expected here.", Conf)), %% invalid cases fall back to minimal mode ?assertEqual(Path++":-23:-42: invalid ranges."++?EOL, rebar_compiler_format:format(Path, {-23,-42}, "", "invalid ranges.", Conf)),