From fe954ec3f29cfff9f421ae967b47fc9aac24c248 Mon Sep 17 00:00:00 2001 From: Magnus Henoch Date: Wed, 22 Jun 2016 13:45:18 +0100 Subject: Show error reason when compiler cannot write file When the compiler fails to write an output file, it used to just print "error writing file". With this change, it also prints the error reason: $ echo "-module(foo)." > foo.erl $ chmod -w . $ erlc foo.erl /tmp/bar/foo.bea#: error writing file: permission denied --- lib/compiler/src/compile.erl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/compiler') diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index 82ff8a95f3..9fdfdadebf 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -236,6 +236,8 @@ format_error({epp,E}) -> epp:format_error(E); format_error(write_error) -> "error writing file"; +format_error({write_error, Error}) -> + io_lib:format("error writing file: ~ts", [file:format_error(Error)]); format_error({rename,From,To,Error}) -> io_lib:format("failed to rename ~ts to ~ts: ~ts", [From,To,file:format_error(Error)]); @@ -1479,8 +1481,8 @@ save_binary_1(St) -> end, {error,St#compile{errors=St#compile.errors ++ Es}} end; - {error,_Error} -> - Es = [{Tfile,[{none,compile,write_error}]}], + {error,Error} -> + Es = [{Tfile,[{none,compile,{write_error,Error}}]}], {error,St#compile{errors=St#compile.errors ++ Es}} end. @@ -1628,8 +1630,8 @@ listing(LFun, Ext, St) -> LFun(Lf, Code), ok = file:close(Lf), {ok,St}; - {error,_Error} -> - Es = [{Lfile,[{none,compile,write_error}]}], + {error,Error} -> + Es = [{Lfile,[{none,compile,{write_error,Error}}]}], {error,St#compile{errors=St#compile.errors ++ Es}} end. -- cgit v1.2.3 From 10ea3707cb220d1b936ce103e78d2a500e6c03e6 Mon Sep 17 00:00:00 2001 From: Magnus Henoch Date: Thu, 23 Jun 2016 10:04:12 +0100 Subject: Fix try-catch when writing makefile Any exceptions at this point would be of class error, not exit. --- lib/compiler/src/compile.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/compiler') diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl index 9fdfdadebf..e2eff2a89b 100644 --- a/lib/compiler/src/compile.erl +++ b/lib/compiler/src/compile.erl @@ -1208,7 +1208,7 @@ makedep_output(#compile{code=Code,options=Opts,ofile=Ofile}=St) -> end, {ok,St} catch - exit:_ -> + error:_ -> %% Couldn't write to output Makefile. Err = {St#compile.ifile,[{none,?MODULE,write_error}]}, {error,St#compile{errors=St#compile.errors++[Err]}} -- cgit v1.2.3