mod_http_upload: Log descriptive error messages

Let file:format_error/1 translate error reasons into descriptive
strings.
This commit is contained in:
Holger Weiss 2015-10-25 00:21:31 +02:00
parent 4936e82bd1
commit 1ff5cbc467
2 changed files with 12 additions and 9 deletions

View File

@ -14,6 +14,7 @@
-define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds. -define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds.
-define(SLOT_TIMEOUT, 18000000). % 5 hours. -define(SLOT_TIMEOUT, 18000000). % 5 hours.
-define(PROCNAME, ?MODULE). -define(PROCNAME, ?MODULE).
-define(FORMAT(Error), file:format_error(Error)).
-define(URL_ENC(URL), binary_to_list(ejabberd_http:url_encode(URL))). -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(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)). -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)]), [Path, ?ADDR_TO_STR(IP)]),
http_response(Host, 404); http_response(Host, 404);
{error, Error} -> {error, Error} ->
?INFO_MSG("Cannot serve ~s to ~s: ~p", ?INFO_MSG("Cannot serve ~s to ~s: ~s",
[Path, ?ADDR_TO_STR(IP), Error]), [Path, ?ADDR_TO_STR(IP), ?FORMAT(Error)]),
http_response(Host, 500) http_response(Host, 500)
end; end;
Error -> Error ->
@ -725,7 +726,7 @@ store_file(Path, Data, FileMode, DirMode) ->
ok = Ok % Raise an exception if file:write/2 failed. ok = Ok % Raise an exception if file:write/2 failed.
catch catch
_:{badmatch, {error, Error}} -> _:{badmatch, {error, Error}} ->
{error, Error}; {error, ?FORMAT(Error)};
_:Error -> _:Error ->
{error, Error} {error, Error}
end. end.
@ -830,7 +831,7 @@ del_tree(Dir) ->
ok = file:del_dir(Dir) ok = file:del_dir(Dir)
catch catch
_:{badmatch, {error, Error}} -> _:{badmatch, {error, Error}} ->
{error, Error}; {error, ?FORMAT(Error)};
_:Error -> _:Error ->
{error, Error} {error, Error}
end. end.

View File

@ -12,6 +12,7 @@
-define(PROCNAME, ?MODULE). -define(PROCNAME, ?MODULE).
-define(TIMEOUT, timer:hours(24)). -define(TIMEOUT, timer:hours(24)).
-define(INITIAL_TIMEOUT, timer:minutes(10)). -define(INITIAL_TIMEOUT, timer:minutes(10)).
-define(FORMAT(Error), file:format_error(Error)).
-behaviour(?GEN_SERVER). -behaviour(?GEN_SERVER).
-behaviour(gen_mod). -behaviour(gen_mod).
@ -205,7 +206,8 @@ handle_info(sweep, #state{server_host = ServerHost,
lists:foreach(fun(UserDir) -> delete_old_files(UserDir, BackThen) end, lists:foreach(fun(UserDir) -> delete_old_files(UserDir, BackThen) end,
UserDirs); UserDirs);
{error, Error} -> {error, Error} ->
?ERROR_MSG("Cannot open document root ~s: ~p", [DocRoot, Error]) ?ERROR_MSG("Cannot open document root ~s: ~s",
[DocRoot, ?FORMAT(Error)])
end, end,
{noreply, State}; {noreply, State};
handle_info(Info, State) -> handle_info(Info, State) ->
@ -308,7 +310,7 @@ gather_file_info(Dir) ->
Acc; Acc;
{error, Error} -> {error, Error} ->
?ERROR_MSG("Cannot stat(2) ~s: ~s", ?ERROR_MSG("Cannot stat(2) ~s: ~s",
[Path, Error]), [Path, ?FORMAT(Error)]),
Acc Acc
end end
end, [], Entries); end, [], Entries);
@ -316,7 +318,7 @@ gather_file_info(Dir) ->
?DEBUG("Directory ~s doesn't exist", [Dir]), ?DEBUG("Directory ~s doesn't exist", [Dir]),
[]; [];
{error, Error} -> {error, Error} ->
?ERROR_MSG("Cannot open directory ~s: ~p", [Dir, Error]), ?ERROR_MSG("Cannot open directory ~s: ~s", [Dir, ?FORMAT(Error)]),
[] []
end. end.
@ -331,10 +333,10 @@ del_file_and_dir(File) ->
ok -> ok ->
?DEBUG("Removed ~s", [Dir]); ?DEBUG("Removed ~s", [Dir]);
{error, Error} -> {error, Error} ->
?INFO_MSG("Cannot remove ~s: ~s", [Dir, Error]) ?INFO_MSG("Cannot remove ~s: ~s", [Dir, ?FORMAT(Error)])
end; end;
{error, Error} -> {error, Error} ->
?WARNING_MSG("Cannot remove ~s: ~s", [File, Error]) ?WARNING_MSG("Cannot remove ~s: ~s", [File, ?FORMAT(Error)])
end. end.
-spec secs_since_epoch() -> non_neg_integer(). -spec secs_since_epoch() -> non_neg_integer().