From d5188093519bc45433a6baf528438cc773307059 Mon Sep 17 00:00:00 2001 From: Serge Aleynikov Date: Wed, 26 Jun 2019 18:20:38 +0600 Subject: Make missing file report more comprehensive --- src/rebar_compiler_erl.erl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/rebar_compiler_erl.erl b/src/rebar_compiler_erl.erl index 1ad16d8..6266743 100644 --- a/src/rebar_compiler_erl.erl +++ b/src/rebar_compiler_erl.erl @@ -74,11 +74,15 @@ needed_files(Graph, FoundFiles, _, AppInfo) -> {OtherErls, ErlOpts ++ AdditionalOpts}}. dependencies(Source, SourceDir, Dirs) -> - {ok, Fd} = file:open(Source, [read]), - Incls = parse_attrs(Fd, [], SourceDir), - AbsIncls = expand_file_names(Incls, Dirs), - ok = file:close(Fd), - AbsIncls. + case file:open(Source, [read]) of + {ok, Fd} -> + Incls = parse_attrs(Fd, [], SourceDir), + AbsIncls = expand_file_names(Incls, Dirs), + ok = file:close(Fd), + AbsIncls; + {error, Reason} -> + throw({cannot_read_file, Source, file:format_error(Reason)}) + end. compile(Source, [{_, OutDir}], Config, ErlOpts) -> case compile:file(Source, [{outdir, OutDir} | ErlOpts]) of -- cgit v1.1 From 86bc08d164dfd84a1633597044fa64de81e18383 Mon Sep 17 00:00:00 2001 From: Serge Aleynikov Date: Wed, 26 Jun 2019 20:29:59 +0600 Subject: Add format_error/1 to print errors nicely --- src/rebar_compiler_erl.erl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rebar_compiler_erl.erl b/src/rebar_compiler_erl.erl index 6266743..a39e906 100644 --- a/src/rebar_compiler_erl.erl +++ b/src/rebar_compiler_erl.erl @@ -6,9 +6,11 @@ needed_files/4, dependencies/3, compile/4, - clean/2]). + clean/2, + format_error/1]). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). context(AppInfo) -> EbinDir = rebar_app_info:ebin_dir(AppInfo), @@ -81,7 +83,7 @@ dependencies(Source, SourceDir, Dirs) -> ok = file:close(Fd), AbsIncls; {error, Reason} -> - throw({cannot_read_file, Source, file:format_error(Reason)}) + throw(?PRV_ERROR({cannot_read_file, Source, file:format_error(Reason)})) end. compile(Source, [{_, OutDir}], Config, ErlOpts) -> @@ -367,3 +369,8 @@ warn_and_find_path(File, Dir) -> [] end end. + +format_error({cannot_read_file, Source, Reason}) -> + lists:flatten(io_lib:format("Cannot read file '~s': ~s", [Source, Reason])); +format_error(Other) -> + io_lib:format("~p", [Other]). -- cgit v1.1