mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-01-26 12:12:25 +00:00
format_error/1 implementations: remove lists:flatten/1 calls, correct return value spec
This commit is contained in:
@@ -165,28 +165,25 @@ find_longopt(_Prefix, _LongOpts, _Candidate) -> ?error.
|
||||
mkerror(Tag, Data) ->
|
||||
{error, {?MODULE, {Tag, Data}}}.
|
||||
|
||||
-spec format_error(term()) -> string().
|
||||
-spec format_error(term()) -> io_lib:chars().
|
||||
format_error(Reason) ->
|
||||
case Reason of
|
||||
{missing_argument, OptCh} ->
|
||||
flatformat("missing argument to -~c", [OptCh]);
|
||||
io_lib:format("missing argument to -~c", [OptCh]);
|
||||
{invalid_option, OptCh} ->
|
||||
flatformat("invalid option -~c", [OptCh]);
|
||||
io_lib:format("invalid option -~c", [OptCh]);
|
||||
{invalid_optstring, OptString} ->
|
||||
flatformat("invalid optstring ~p", [OptString]);
|
||||
io_lib:format("invalid optstring ~p", [OptString]);
|
||||
{invalid_argument_long, Prefix} ->
|
||||
flatformat("invalid argument to --~s", [Prefix]);
|
||||
io_lib:format("invalid argument to --~s", [Prefix]);
|
||||
{missing_argument_long, Prefix} ->
|
||||
flatformat("missing argument to --~s", [Prefix]);
|
||||
io_lib:format("missing argument to --~s", [Prefix]);
|
||||
{invalid_longopts, LongOpts} ->
|
||||
flatformat("invalid longopts ~p", [LongOpts]);
|
||||
io_lib:format("invalid longopts ~p", [LongOpts]);
|
||||
{invalid_option_long, Prefix} ->
|
||||
flatformat("invalid option --~s", [Prefix]);
|
||||
io_lib:format("invalid option --~s", [Prefix]);
|
||||
{ambiguous_option, Prefix} ->
|
||||
flatformat("ambiguous option --~s", [Prefix]);
|
||||
io_lib:format("ambiguous option --~s", [Prefix]);
|
||||
_ ->
|
||||
flatformat("~p", [Reason])
|
||||
io_lib:format("~p", [Reason])
|
||||
end.
|
||||
|
||||
flatformat(Fmt, Args) ->
|
||||
lists:flatten(io_lib:format(Fmt, Args)).
|
||||
|
||||
@@ -150,25 +150,25 @@ stdin() ->
|
||||
stdout() ->
|
||||
do_open(stdout).
|
||||
|
||||
-spec format_error(term()) -> string().
|
||||
-spec format_error(term()) -> io_lib:chars().
|
||||
format_error(Reason) ->
|
||||
case Reason of
|
||||
{bad_request, Req} ->
|
||||
flatformat("bad request ~p", [Req]);
|
||||
io_lib:format("bad request ~p", [Req]);
|
||||
no_io_direction ->
|
||||
"no I/O direction";
|
||||
{bad_mode, Mode} ->
|
||||
flatformat("bad mode ~p", [Mode]);
|
||||
io_lib:format("bad mode ~p", [Mode]);
|
||||
{bad_fread, Size, NMemb} ->
|
||||
flatformat("bad fread size ~p nmemb ~p", [Size, NMemb]);
|
||||
io_lib:format("bad fread size ~p nmemb ~p", [Size, NMemb]);
|
||||
eof ->
|
||||
"end-of-file during fread";
|
||||
write_only ->
|
||||
"read from write-only file";
|
||||
{bad_whence, Whence} ->
|
||||
flatformat("bad whence ~p", [Whence]);
|
||||
io_lib:format("bad whence ~p", [Whence]);
|
||||
_ ->
|
||||
flatformat("~p", [Reason])
|
||||
io_lib:format("~p", [Reason])
|
||||
end.
|
||||
|
||||
%% gen_server callbacks --------------------------------------------------------
|
||||
@@ -700,6 +700,3 @@ mkerror(Reason) ->
|
||||
|
||||
mkfileerror(Reason) ->
|
||||
{error, {file, Reason}}.
|
||||
|
||||
flatformat(Fmt, Args) ->
|
||||
lists:flatten(io_lib:format(Fmt, Args)).
|
||||
|
||||
@@ -130,10 +130,10 @@ digit_value(C) ->
|
||||
mkerror(Tag) ->
|
||||
{error, {?MODULE, Tag}}.
|
||||
|
||||
-spec format_error(term()) -> string().
|
||||
-spec format_error(term()) -> io_lib:chars().
|
||||
format_error(Reason) ->
|
||||
case Reason of
|
||||
no_digits -> "no valid digits found";
|
||||
invalid_base -> "invalid base";
|
||||
_ -> lists:flatten(io_lib:format("~p", [Reason]))
|
||||
_ -> io_lib:format("~p", [Reason])
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user