Skip to main content

src/version_bump@error.erl

-module(version_bump@error).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/version_bump/error.gleam").
-export([to_string/1]).
-export_type([release_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 for the release pipeline. Mirrors semantic-release's use of\n"
    " AggregateError to collect multiple problems before failing.\n"
).

-type release_error() :: {config_error, binary()} |
    {git_error, binary()} |
    {plugin_error, binary(), binary()} |
    {version_error, binary()} |
    {network_error, binary()} |
    {validation_error, binary()} |
    {aggregate_error, list(release_error())}.

-file("src/version_bump/error.gleam", 18).
-spec to_string(release_error()) -> binary().
to_string(Error) ->
    case Error of
        {config_error, M} ->
            <<"Config error: "/utf8, M/binary>>;

        {git_error, M@1} ->
            <<"Git error: "/utf8, M@1/binary>>;

        {plugin_error, P, M@2} ->
            <<<<<<"Plugin '"/utf8, P/binary>>/binary, "' error: "/utf8>>/binary,
                M@2/binary>>;

        {version_error, M@3} ->
            <<"Version error: "/utf8, M@3/binary>>;

        {network_error, M@4} ->
            <<"Network error: "/utf8, M@4/binary>>;

        {validation_error, M@5} ->
            <<"Validation error: "/utf8, M@5/binary>>;

        {aggregate_error, Errs} ->
            <<"Multiple errors:\n"/utf8,
                (gleam@string:join(
                    gleam@list:map(Errs, fun to_string/1),
                    <<"\n"/utf8>>
                ))/binary>>
    end.