Packages

Typed environment variable readers for Gleam built on top of envoy.

Current section

Files

Jump to
envoker src envoker@error.erl
Raw

src/envoker@error.erl

-module(envoker@error).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src\\envoker\\error.gleam").
-export([to_string/1]).
-export_type([env_field_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.
-type env_field_error() :: {empty_field_error, binary()} |
{missing_field_error, binary()} |
{parse_field_error,
binary(),
binary(),
binary(),
gleam@option:option(binary())}.
-file("src\\envoker\\error.gleam", 16).
?DOC(" Converts a structured error into a readable message.\n").
-spec to_string(env_field_error()) -> binary().
to_string(Error) ->
case Error of
{empty_field_error, Field_name} ->
<<<<"Empty value in '"/utf8, Field_name/binary>>/binary, "'"/utf8>>;
{missing_field_error, Field_name@1} ->
<<<<"Missing environment variable '"/utf8, Field_name@1/binary>>/binary,
"'."/utf8>>;
{parse_field_error, Field_name@2, Expected_type, Field_value, Details} ->
<<<<<<<<<<<<"Failed to parse field '"/utf8, Field_name@2/binary>>/binary,
"' with value '"/utf8>>/binary,
Field_value/binary>>/binary,
"'. Expected type: "/utf8>>/binary,
Expected_type/binary>>/binary,
(case Details of
{some, Text} ->
<<". Details: "/utf8, Text/binary>>;
none ->
<<""/utf8>>
end)/binary>>
end.