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(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.

View File

@ -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().