Packages

A type-safe configuration loader for Gleam that supports JSON, YAML, and TOML with automatic format detection, environment variable resolution, and profile-based configuration.

Current section

Files

Jump to
yodel src yodel@errors.erl
Raw

src/yodel@errors.erl

-module(yodel@errors).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/yodel/errors.gleam").
-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, properties_error/0, type_error/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Error types returned when loading, parsing, or accessing configuration.\n"
"\n"
" **Note:** These types are re-exported from the main `yodel` module.\n"
" Import them via `import yodel` rather than importing this module directly.\n"
).
-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()} |
{not_a_file, 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()}.
-type properties_error() :: {path_not_found, binary()} |
{type_error, binary(), type_error()}.
-type type_error() :: {expected_string, yodel@value:value()} |
{expected_int, yodel@value:value()} |
{expected_float, yodel@value:value()} |
{expected_bool, yodel@value:value()}.
-file("src/yodel/errors.gleam", 82).
-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>>;
{not_a_file, Path@2} ->
<<"Not a file: "/utf8, Path@2/binary>>
end.
-file("src/yodel/errors.gleam", 99).
-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", 91).
-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", 112).
-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", 125).
-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", 72).
?DOC(" Format a `ConfigError` into a human-readable string.\n").
-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.