Current section
Files
Jump to
Current section
Files
src/drip@internal@error.erl
-module(drip@internal@error).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/drip/internal/error.gleam").
-export([describe/1]).
-export_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(false).
-type error() :: {invalid_usage, binary()} |
{no_elements_requested, binary()} |
{failed_to_find_project_root, binary()} |
{failed_to_read_gleam_toml, simplifile:file_error()} |
{failed_to_parse_gleam_toml, tomlet:parse_error()} |
{failed_to_get_gleam_toml_value, tomlet:get_error()} |
{failed_to_edit_gleam_toml, tomlet:edit_error()} |
{invalid_prefix, binary()} |
{failed_to_check_if_project_file_exists, binary(), simplifile:file_error()} |
{failed_to_read_project_directory, binary(), simplifile:file_error()} |
{failed_to_create_project_directory, binary(), simplifile:file_error()} |
{failed_to_write_project_file, binary(), simplifile:file_error()} |
{failed_to_read_project_file, binary(), simplifile:file_error()} |
{failed_to_delete_project_file, binary(), simplifile:file_error()} |
{project_file_already_exists, binary()} |
{failed_to_find_index_stylesheet, binary()} |
empty_source |
{invalid_source_url, binary()} |
{source_not_found, binary()} |
{source_returned_bad_status, binary(), integer()} |
{failed_to_fetch_source_file, binary(), gleam@httpc:http_error()} |
{failed_to_read_source_file, binary(), simplifile:file_error()} |
{unsupported_registry_schema_version, integer(), integer()} |
{failed_to_decode_registry_file, binary(), gleam@json:decode_error()} |
{unknown_element, binary()} |
{unsupported_registry_file, binary(), binary()}.
-file("src/drip/internal/error.gleam", 292).
?DOC(false).
-spec quote(binary()) -> binary().
quote(Value) ->
<<<<"\""/utf8, Value/binary>>/binary, "\""/utf8>>.
-file("src/drip/internal/error.gleam", 281).
?DOC(false).
-spec describe_field_error(gleam@dynamic@decode:decode_error()) -> binary().
describe_field_error(Error) ->
{decode_error, Expected, Found, Path} = Error,
Location = case Path of
[] ->
<<""/utf8>>;
_ ->
<<" at "/utf8,
(quote(gleam@string:join(Path, <<"."/utf8>>)))/binary>>
end,
<<<<<<<<"expected "/utf8, Expected/binary>>/binary, " but found "/utf8>>/binary,
Found/binary>>/binary,
Location/binary>>.
-file("src/drip/internal/error.gleam", 268).
?DOC(false).
-spec describe_decode_error(gleam@json:decode_error()) -> binary().
describe_decode_error(Error) ->
case Error of
unexpected_end_of_input ->
<<"the file ended unexpectedly."/utf8>>;
{unexpected_byte, Byte} ->
<<<<"unexpected byte "/utf8, (quote(Byte))/binary>>/binary,
"."/utf8>>;
{unexpected_sequence, Sequence} ->
<<<<"unexpected sequence "/utf8, (quote(Sequence))/binary>>/binary,
"."/utf8>>;
{unable_to_decode, Errors} ->
<<<<"the contents don't match the expected registry format ("/utf8,
(begin
_pipe = Errors,
_pipe@1 = gleam@list:map(
_pipe,
fun describe_field_error/1
),
gleam@string:join(_pipe@1, <<", "/utf8>>)
end)/binary>>/binary,
")."/utf8>>
end.
-file("src/drip/internal/error.gleam", 261).
?DOC(false).
-spec describe_connect_error(gleam@httpc:connect_error()) -> binary().
describe_connect_error(Error) ->
case Error of
{posix, Code} ->
Code;
{tls_alert, Code@1, Detail} ->
<<<<<<Code@1/binary, " ("/utf8>>/binary, Detail/binary>>/binary,
")"/utf8>>
end.
-file("src/drip/internal/error.gleam", 248).
?DOC(false).
-spec describe_http_error(gleam@httpc:http_error()) -> binary().
describe_http_error(Error) ->
case Error of
invalid_utf8_response ->
<<"response body was not valid UTF-8."/utf8>>;
response_timeout ->
<<"response timed out."/utf8>>;
{failed_to_connect, Ip4, Ip6} ->
<<<<<<<<"failed to connect (ipv4: "/utf8,
(describe_connect_error(Ip4))/binary>>/binary,
", ipv6: "/utf8>>/binary,
(describe_connect_error(Ip6))/binary>>/binary,
")."/utf8>>
end.
-file("src/drip/internal/error.gleam", 296).
?DOC(false).
-spec quote_key(list(binary())) -> binary().
quote_key(Key) ->
quote(gleam@string:join(Key, <<"."/utf8>>)).
-file("src/drip/internal/error.gleam", 230).
?DOC(false).
-spec describe_edit_error(tomlet:edit_error()) -> binary().
describe_edit_error(Error) ->
case Error of
empty_key_path ->
<<"the edit key path was empty."/utf8>>;
{invalid_key_segment, Segment} ->
<<<<"the key segment "/utf8, (quote(Segment))/binary>>/binary,
" cannot be written as TOML."/utf8>>;
invalid_comment_text ->
<<"a comment spanned more than one line."/utf8>>;
{missing_edit_key, Key} ->
<<<<"no value exists at "/utf8, (quote_key(Key))/binary>>/binary,
"."/utf8>>;
{key_conflict, Key@1} ->
<<(quote_key(Key@1))/binary,
" conflicts with an existing value."/utf8>>;
{inline_table_insert_unsupported, Key@2} ->
<<<<"cannot insert "/utf8, (quote_key(Key@2))/binary>>/binary,
" into an existing inline table; rewrite it as a [tools.drip] section."/utf8>>;
invalid_value ->
<<"the value can't be represented here."/utf8>>
end.
-file("src/drip/internal/error.gleam", 218).
?DOC(false).
-spec describe_expected_type(tomlet:expected_type()) -> binary().
describe_expected_type(Expected) ->
case Expected of
expected_string ->
<<"a string"/utf8>>;
expected_int ->
<<"an integer"/utf8>>;
expected_bool ->
<<"a boolean"/utf8>>;
expected_float ->
<<"a float"/utf8>>;
expected_date ->
<<"a date"/utf8>>;
expected_time ->
<<"a time"/utf8>>;
expected_date_time ->
<<"a date-time"/utf8>>
end.
-file("src/drip/internal/error.gleam", 205).
?DOC(false).
-spec describe_get_error(tomlet:get_error()) -> binary().
describe_get_error(Error) ->
case Error of
{key_not_found, Key} ->
<<<<"missing the required key "/utf8, (quote_key(Key))/binary>>/binary,
"."/utf8>>;
{wrong_type, Key@1, Expected} ->
<<<<<<<<"expected "/utf8, (quote_key(Key@1))/binary>>/binary,
" to be "/utf8>>/binary,
(describe_expected_type(Expected))/binary>>/binary,
"."/utf8>>
end.
-file("src/drip/internal/error.gleam", 196).
?DOC(false).
-spec describe_syntax_error(tomlet:syntax_error_kind()) -> binary().
describe_syntax_error(Kind) ->
case Kind of
expected_value ->
<<"expected a value"/utf8>>;
expected_key ->
<<"expected a key"/utf8>>;
expected_table_header ->
<<"expected a table header"/utf8>>;
invalid_toml ->
<<"invalid TOML"/utf8>>
end.
-file("src/drip/internal/error.gleam", 183).
?DOC(false).
-spec describe_parse_error(tomlet:parse_error()) -> binary().
describe_parse_error(Error) ->
case Error of
invalid_encoding ->
<<"the file is not valid UTF-8."/utf8>>;
{invalid_syntax, Kind, Offset} ->
<<<<<<(describe_syntax_error(Kind))/binary,
" at byte offset "/utf8>>/binary,
(erlang:integer_to_binary(Offset))/binary>>/binary,
"."/utf8>>;
{duplicate_key, Key, _} ->
<<<<"the key "/utf8, (quote_key(Key))/binary>>/binary,
" is defined more than once."/utf8>>
end.
-file("src/drip/internal/error.gleam", 53).
?DOC(false).
-spec describe(error()) -> binary().
describe(Error) ->
case Error of
{invalid_usage, Message} ->
Message;
{no_elements_requested, Command} ->
<<<<<<<<"No elements requested. "/utf8,
(gleam@string:capitalise(Command))/binary>>/binary,
" one or more elements by name using gleam run -m drip -- "/utf8>>/binary,
Command/binary>>/binary,
" <element>."/utf8>>;
{failed_to_find_project_root, Path} ->
Location = case Path of
<<"./"/utf8>> ->
<<"the current directory"/utf8>>;
_ ->
quote(Path)
end,
<<<<"Failed to find gleam.toml in "/utf8, Location/binary>>/binary,
" or any parent directory. Ensure you're inside a Gleam project."/utf8>>;
{failed_to_read_gleam_toml, Cause} ->
<<<<"Failed to read gleam.toml: "/utf8,
(simplifile:describe_error(Cause))/binary>>/binary,
"."/utf8>>;
{failed_to_parse_gleam_toml, Cause@1} ->
<<"Failed to parse gleam.toml: "/utf8,
(describe_parse_error(Cause@1))/binary>>;
{failed_to_get_gleam_toml_value, Cause@2} ->
<<"Failed to get gleam.toml value: "/utf8,
(describe_get_error(Cause@2))/binary>>;
{failed_to_edit_gleam_toml, Cause@3} ->
<<"Failed to update gleam.toml: "/utf8,
(describe_edit_error(Cause@3))/binary>>;
{invalid_prefix, Got} ->
<<<<<<"The prefix "/utf8, (quote(Got))/binary>>/binary,
" isn't a valid module path. Use lowercase identifier segments like"/utf8>>/binary,
" ui or lib/ui."/utf8>>;
{failed_to_check_if_project_file_exists, Path@1, Cause@4} ->
<<<<<<<<"Failed to check whether a file exists at "/utf8,
(quote(Path@1))/binary>>/binary,
": "/utf8>>/binary,
(simplifile:describe_error(Cause@4))/binary>>/binary,
"."/utf8>>;
{failed_to_read_project_directory, Path@2, Cause@5} ->
<<<<<<<<"Failed to list the contents of "/utf8,
(quote(Path@2))/binary>>/binary,
": "/utf8>>/binary,
(simplifile:describe_error(Cause@5))/binary>>/binary,
"."/utf8>>;
{failed_to_create_project_directory, Path@3, Cause@6} ->
<<<<<<<<"Failed to create the parent directory for "/utf8,
(quote(Path@3))/binary>>/binary,
": "/utf8>>/binary,
(simplifile:describe_error(Cause@6))/binary>>/binary,
"."/utf8>>;
{failed_to_write_project_file, Path@4, Cause@7} ->
<<<<<<<<"Failed to write "/utf8, (quote(Path@4))/binary>>/binary,
": "/utf8>>/binary,
(simplifile:describe_error(Cause@7))/binary>>/binary,
"."/utf8>>;
{failed_to_read_project_file, Path@5, Cause@8} ->
<<<<<<<<"Failed to read "/utf8, (quote(Path@5))/binary>>/binary,
": "/utf8>>/binary,
(simplifile:describe_error(Cause@8))/binary>>/binary,
"."/utf8>>;
{failed_to_delete_project_file, Path@6, Cause@9} ->
<<<<<<<<"Failed to delete "/utf8, (quote(Path@6))/binary>>/binary,
": "/utf8>>/binary,
(simplifile:describe_error(Cause@9))/binary>>/binary,
"."/utf8>>;
{project_file_already_exists, Path@7} ->
<<(quote(Path@7))/binary,
" already exists. Pass --force to overwrite."/utf8>>;
{failed_to_find_index_stylesheet, Path@8} ->
<<<<"Failed to find index stylesheet at "/utf8,
(quote(Path@8))/binary>>/binary,
". Initialize your project with gleam run -m drip -- init."/utf8>>;
empty_source ->
<<"The source is empty. Set it to a URL or path, or remove it to use the"/utf8,
" default."/utf8>>;
{invalid_source_url, Url} ->
<<<<"The source isn't a valid URL: "/utf8, (quote(Url))/binary>>/binary,
"."/utf8>>;
{source_not_found, Location@1} ->
<<<<"Failed to find the source file at "/utf8,
(quote(Location@1))/binary>>/binary,
". Check that the source points at a valid registry."/utf8>>;
{source_returned_bad_status, Url@1, Status} ->
<<<<<<<<"Failed to fetch the source file at "/utf8,
(quote(Url@1))/binary>>/binary,
": received HTTP status code "/utf8>>/binary,
(erlang:integer_to_binary(Status))/binary>>/binary,
"."/utf8>>;
{failed_to_fetch_source_file, Url@2, Cause@10} ->
<<<<<<"Failed to fetch the source file at "/utf8,
(quote(Url@2))/binary>>/binary,
": "/utf8>>/binary,
(describe_http_error(Cause@10))/binary>>;
{failed_to_read_source_file, Path@9, Cause@11} ->
<<<<<<<<"Failed to read the source file at "/utf8,
(quote(Path@9))/binary>>/binary,
": "/utf8>>/binary,
(simplifile:describe_error(Cause@11))/binary>>/binary,
"."/utf8>>;
{unsupported_registry_schema_version, Found, Supported} ->
<<<<<<<<"This registry is on schema version "/utf8,
(erlang:integer_to_binary(Found))/binary>>/binary,
", but this version of drip only supports schema versions up to "/utf8>>/binary,
(erlang:integer_to_binary(Supported))/binary>>/binary,
". Update drip to use this registry."/utf8>>;
{failed_to_decode_registry_file, Path@10, Cause@12} ->
<<<<<<"Failed to decode the registry file at "/utf8,
(quote(Path@10))/binary>>/binary,
": "/utf8>>/binary,
(describe_decode_error(Cause@12))/binary>>;
{unknown_element, Name} ->
<<<<"No element named "/utf8, (quote(Name))/binary>>/binary,
" in the registry. See what's available with gleam run -m drip -- list."/utf8>>;
{unsupported_registry_file, Element, File} ->
<<<<<<<<"The registry entry "/utf8, (quote(Element))/binary>>/binary,
" lists an unsupported file path "/utf8>>/binary,
(quote(File))/binary>>/binary,
". Registry file names must be plain names, without \"/\", \"\\\", or \"..\"."/utf8>>
end.