From 1ff5cbc46722e9069a5ddc30483016fb033d1cb3 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sun, 25 Oct 2015 00:21:31 +0200 Subject: [PATCH] mod_http_upload: Log descriptive error messages Let file:format_error/1 translate error reasons into descriptive strings. --- mod_http_upload/src/mod_http_upload.erl | 9 +++++---- mod_http_upload/src/mod_http_upload_quota.erl | 12 +++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mod_http_upload/src/mod_http_upload.erl b/mod_http_upload/src/mod_http_upload.erl index 7760fe2..cc1050b 100644 --- a/mod_http_upload/src/mod_http_upload.erl +++ b/mod_http_upload/src/mod_http_upload.erl @@ -14,6 +14,7 @@ -define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds. -define(SLOT_TIMEOUT, 18000000). % 5 hours. -define(PROCNAME, ?MODULE). +-define(FORMAT(Error), file:format_error(Error)). -define(URL_ENC(URL), binary_to_list(ejabberd_http:url_encode(URL))). -define(ADDR_TO_STR(IP), ejabberd_config:may_hide_data(jlib:ip_to_list(IP))). -define(STR_TO_INT(Str, B), jlib:binary_to_integer(iolist_to_binary(Str), B)). @@ -407,8 +408,8 @@ process(LocalPath, #request{method = Method, host = Host, ip = IP}) [Path, ?ADDR_TO_STR(IP)]), http_response(Host, 404); {error, Error} -> - ?INFO_MSG("Cannot serve ~s to ~s: ~p", - [Path, ?ADDR_TO_STR(IP), Error]), + ?INFO_MSG("Cannot serve ~s to ~s: ~s", + [Path, ?ADDR_TO_STR(IP), ?FORMAT(Error)]), http_response(Host, 500) end; Error -> @@ -725,7 +726,7 @@ store_file(Path, Data, FileMode, DirMode) -> ok = Ok % Raise an exception if file:write/2 failed. catch _:{badmatch, {error, Error}} -> - {error, Error}; + {error, ?FORMAT(Error)}; _:Error -> {error, Error} end. @@ -830,7 +831,7 @@ del_tree(Dir) -> ok = file:del_dir(Dir) catch _:{badmatch, {error, Error}} -> - {error, Error}; + {error, ?FORMAT(Error)}; _:Error -> {error, Error} end. diff --git a/mod_http_upload/src/mod_http_upload_quota.erl b/mod_http_upload/src/mod_http_upload_quota.erl index 3abea3f..9fb5760 100644 --- a/mod_http_upload/src/mod_http_upload_quota.erl +++ b/mod_http_upload/src/mod_http_upload_quota.erl @@ -12,6 +12,7 @@ -define(PROCNAME, ?MODULE). -define(TIMEOUT, timer:hours(24)). -define(INITIAL_TIMEOUT, timer:minutes(10)). +-define(FORMAT(Error), file:format_error(Error)). -behaviour(?GEN_SERVER). -behaviour(gen_mod). @@ -205,7 +206,8 @@ handle_info(sweep, #state{server_host = ServerHost, lists:foreach(fun(UserDir) -> delete_old_files(UserDir, BackThen) end, UserDirs); {error, Error} -> - ?ERROR_MSG("Cannot open document root ~s: ~p", [DocRoot, Error]) + ?ERROR_MSG("Cannot open document root ~s: ~s", + [DocRoot, ?FORMAT(Error)]) end, {noreply, State}; handle_info(Info, State) -> @@ -308,7 +310,7 @@ gather_file_info(Dir) -> Acc; {error, Error} -> ?ERROR_MSG("Cannot stat(2) ~s: ~s", - [Path, Error]), + [Path, ?FORMAT(Error)]), Acc end end, [], Entries); @@ -316,7 +318,7 @@ gather_file_info(Dir) -> ?DEBUG("Directory ~s doesn't exist", [Dir]), []; {error, Error} -> - ?ERROR_MSG("Cannot open directory ~s: ~p", [Dir, Error]), + ?ERROR_MSG("Cannot open directory ~s: ~s", [Dir, ?FORMAT(Error)]), [] end. @@ -331,10 +333,10 @@ del_file_and_dir(File) -> ok -> ?DEBUG("Removed ~s", [Dir]); {error, Error} -> - ?INFO_MSG("Cannot remove ~s: ~s", [Dir, Error]) + ?INFO_MSG("Cannot remove ~s: ~s", [Dir, ?FORMAT(Error)]) end; {error, Error} -> - ?WARNING_MSG("Cannot remove ~s: ~s", [File, Error]) + ?WARNING_MSG("Cannot remove ~s: ~s", [File, ?FORMAT(Error)]) end. -spec secs_since_epoch() -> non_neg_integer().