Current section

Files

Jump to
cactus src cactus@errors.erl
Raw

src/cactus@errors.erl

-module(cactus@errors).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([as_err/2, as_invalid_field_err/1, as_fs_err/2, str/1]).
-export_type([cactus_err/0]).
-type cactus_err() :: {invalid_field_err, tom:get_error()} |
invalid_toml_err |
{action_failed_err, binary()} |
{fs_err, binary(), simplifile:file_error()} |
{cli_err, binary()} |
none.
-spec as_err({ok, LDF} | {error, any()}, cactus_err()) -> {ok, LDF} |
{error, cactus_err()}.
as_err(Res, Err) ->
gleam@result:replace_error(Res, Err).
-spec as_invalid_field_err({ok, LDL} | {error, tom:get_error()}) -> {ok, LDL} |
{error, cactus_err()}.
as_invalid_field_err(Res) ->
case Res of
{ok, _} ->
as_err(Res, none);
{error, Get_error} ->
as_err(Res, {invalid_field_err, Get_error})
end.
-spec as_fs_err({ok, LDQ} | {error, simplifile:file_error()}, binary()) -> {ok,
LDQ} |
{error, cactus_err()}.
as_fs_err(Res, Path) ->
case Res of
{ok, _} ->
as_err(Res, none);
{error, File_error} ->
as_err(Res, {fs_err, Path, File_error})
end.
-spec str(cactus_err()) -> binary().
str(Err) ->
case Err of
{invalid_field_err, {not_found, Keys}} ->
<<<<"Missing field in config: '"/utf8,
(gleam@string:join(Keys, <<"."/utf8>>))/binary>>/binary,
"'"/utf8>>;
{invalid_field_err, {wrong_type, Keys@1, Expected, Got}} ->
<<<<<<<<<<<<"Invalid field in config: '"/utf8,
(gleam@string:join(Keys@1, <<"."/utf8>>))/binary>>/binary,
"' expected: '"/utf8>>/binary,
Expected/binary>>/binary,
"' got '"/utf8>>/binary,
Got/binary>>/binary,
"'"/utf8>>;
invalid_toml_err ->
<<"InvalidTomlErr"/utf8>>;
{action_failed_err, Output} ->
<<"ActionFailedErr:\n"/utf8, Output/binary>>;
{fs_err, Path, Err@1} ->
<<<<<<"FSErr at "/utf8, Path/binary>>/binary, " with "/utf8>>/binary,
(simplifile:describe_error(Err@1))/binary>>;
{cli_err, Arg} ->
<<<<"CLIErr: invalid arg '"/utf8, Arg/binary>>/binary, "'"/utf8>>;
none ->
erlang:error(#{gleam_error => panic,
message => <<"how?"/utf8>>,
module => <<"cactus/errors"/utf8>>,
function => <<"str"/utf8>>,
line => 52})
end.