mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Gracefully report invalid encoding of a translation file
This commit is contained in:
parent
b0379db5a1
commit
6fd736d496
@ -40,7 +40,8 @@
|
|||||||
-define(ZERO_DATETIME, {{0,0,0}, {0,0,0}}).
|
-define(ZERO_DATETIME, {{0,0,0}, {0,0,0}}).
|
||||||
|
|
||||||
-type error_reason() :: file:posix() | {integer(), module(), term()} |
|
-type error_reason() :: file:posix() | {integer(), module(), term()} |
|
||||||
badarg | terminated | system_limit | bad_file.
|
badarg | terminated | system_limit | bad_file |
|
||||||
|
bad_encoding.
|
||||||
|
|
||||||
-record(state, {}).
|
-record(state, {}).
|
||||||
|
|
||||||
@ -146,9 +147,13 @@ load_file(File) ->
|
|||||||
{ok, Lines} ->
|
{ok, Lines} ->
|
||||||
lists:map(
|
lists:map(
|
||||||
fun({In, Out}) ->
|
fun({In, Out}) ->
|
||||||
InB = iolist_to_binary(In),
|
try
|
||||||
OutB = iolist_to_binary(Out),
|
InB = unicode:characters_to_binary(In, utf8),
|
||||||
{{Lang, InB}, OutB};
|
OutB = unicode:characters_to_binary(Out, utf8),
|
||||||
|
{{Lang, InB}, OutB}
|
||||||
|
catch _:badarg ->
|
||||||
|
{error, File, bad_encoding}
|
||||||
|
end;
|
||||||
(_) ->
|
(_) ->
|
||||||
{error, File, bad_file}
|
{error, File, bad_file}
|
||||||
end, Lines);
|
end, Lines);
|
||||||
@ -289,6 +294,8 @@ lang_of_file(FileName) ->
|
|||||||
-spec format_error(error_reason()) -> string().
|
-spec format_error(error_reason()) -> string().
|
||||||
format_error(bad_file) ->
|
format_error(bad_file) ->
|
||||||
"corrupted or invalid translation file";
|
"corrupted or invalid translation file";
|
||||||
|
format_error(bad_encoding) ->
|
||||||
|
"not an UTF-8 encoding";
|
||||||
format_error({_, _, _} = Reason) ->
|
format_error({_, _, _} = Reason) ->
|
||||||
"at line " ++ file:format_error(Reason);
|
"at line " ++ file:format_error(Reason);
|
||||||
format_error(Reason) ->
|
format_error(Reason) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user