Current section
Files
Jump to
Current section
Files
src/yodel@errors.erl
-module(yodel@errors).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([format_config_error/1]).
-export_type([config_error/0, file_error/0, parse_error/0, syntax_error/0, location/0, resolver_error/0, validation_error/0]).
-type config_error() :: {file_error, file_error()} |
{parse_error, parse_error()} |
{resolver_error, resolver_error()} |
{validation_error, validation_error()}.
-type file_error() :: {file_not_found, binary()} |
{file_permission_denied, binary()} |
{file_read_error, binary()}.
-type parse_error() :: {invalid_syntax, syntax_error()} |
{invalid_structure, binary()} |
unknown_format.
-type syntax_error() :: {syntax_error, binary(), location(), binary()}.
-type location() :: {location, integer(), integer()}.
-type resolver_error() :: {unresolved_placeholder, binary(), binary()} |
{regex_error, binary()} |
no_placeholder_found.
-type validation_error() :: empty_config | {invalid_config, binary()}.
-file("src/yodel/errors.gleam", 51).
-spec format_file_error(file_error()) -> binary().
format_file_error(Error) ->
case Error of
{file_not_found, Path} ->
<<"File not found: "/utf8, Path/binary>>;
{file_permission_denied, Path@1} ->
<<"Permission denied: "/utf8, Path@1/binary>>;
{file_read_error, Details} ->
<<"Error reading file: "/utf8, Details/binary>>
end.
-file("src/yodel/errors.gleam", 67).
-spec format_syntax_error(syntax_error()) -> binary().
format_syntax_error(Error) ->
{syntax_error, Format, Location, Message} = Error,
{location, Line, Column} = Location,
<<<<<<<<<<<<<<"Syntax error in "/utf8, Format/binary>>/binary,
" at line "/utf8>>/binary,
(erlang:integer_to_binary(Line))/binary>>/binary,
", column "/utf8>>/binary,
(erlang:integer_to_binary(Column))/binary>>/binary,
": "/utf8>>/binary,
Message/binary>>.
-file("src/yodel/errors.gleam", 59).
-spec format_parse_error(parse_error()) -> binary().
format_parse_error(Error) ->
case Error of
{invalid_syntax, Error@1} ->
format_syntax_error(Error@1);
{invalid_structure, Details} ->
Details;
unknown_format ->
<<"Unable to determine config format"/utf8>>
end.
-file("src/yodel/errors.gleam", 80).
-spec format_resolve_error(resolver_error()) -> binary().
format_resolve_error(Error) ->
case Error of
{unresolved_placeholder, Placeholder, Value} ->
<<<<<<<<"Could not resolve placeholder '"/utf8, Placeholder/binary>>/binary,
"' in value \""/utf8>>/binary,
Value/binary>>/binary,
"\""/utf8>>;
{regex_error, Details} ->
<<"Regex error: "/utf8, Details/binary>>;
no_placeholder_found ->
<<"No placeholder found"/utf8>>
end.
-file("src/yodel/errors.gleam", 93).
-spec format_validation_error(validation_error()) -> binary().
format_validation_error(Error) ->
case Error of
empty_config ->
<<"Empty config"/utf8>>;
{invalid_config, Details} ->
<<"Invalid config: "/utf8, Details/binary>>
end.
-file("src/yodel/errors.gleam", 41).
-spec format_config_error(config_error()) -> binary().
format_config_error(Error) ->
case Error of
{file_error, File_error} ->
format_file_error(File_error);
{parse_error, Parse_error} ->
format_parse_error(Parse_error);
{resolver_error, Resolve_error} ->
format_resolve_error(Resolve_error);
{validation_error, Validation_error} ->
format_validation_error(Validation_error)
end.