Current section
Files
Jump to
Current section
Files
src/glean@error.erl
-module(glean@error).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glean/error.gleam").
-export([to_string/1]).
-export_type([glean_error/0, validation_error/0, finish_reason/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 glean_error() :: {provider_error, binary(), binary(), integer(), binary()} |
{tool_not_found, binary()} |
{tool_execution_error, binary(), binary(), binary()} |
{tool_input_validation_error, binary(), binary(), list(validation_error())} |
{output_validation_error, list(validation_error())} |
{max_steps_exceeded, integer(), integer()} |
{json_parse_error, binary(), binary()} |
{timeout, integer()} |
{config_error, binary()}.
-type validation_error() :: {validation_error, list(binary()), binary()}.
-type finish_reason() :: stop |
length |
content_filter |
tool_calls |
finish_error |
{other, binary()}.
-file("src/glean/error.gleam", 46).
?DOC(" Convert a GleanError to a human-readable string.\n").
-spec to_string(glean_error()) -> binary().
to_string(Error) ->
case Error of
{provider_error, Provider, Model, Status, Message} ->
<<<<<<<<<<<<<<"ProviderError("/utf8, Provider/binary>>/binary,
", "/utf8>>/binary,
Model/binary>>/binary,
", status="/utf8>>/binary,
(erlang:integer_to_binary(Status))/binary>>/binary,
"): "/utf8>>/binary,
(gleam@string:slice(Message, 0, 200))/binary>>;
{tool_not_found, Name} ->
<<"ToolNotFound: "/utf8, Name/binary>>;
{tool_execution_error, Name@1, _, Reason} ->
<<<<<<"ToolExecutionError("/utf8, Name@1/binary>>/binary,
"): "/utf8>>/binary,
Reason/binary>>;
{tool_input_validation_error, Name@2, _, _} ->
<<<<"ToolInputValidationError("/utf8, Name@2/binary>>/binary,
")"/utf8>>;
{output_validation_error, _} ->
<<"OutputValidationError"/utf8>>;
{max_steps_exceeded, Max, Taken} ->
<<<<<<<<"MaxStepsExceeded(max="/utf8,
(erlang:integer_to_binary(Max))/binary>>/binary,
", taken="/utf8>>/binary,
(erlang:integer_to_binary(Taken))/binary>>/binary,
")"/utf8>>;
{json_parse_error, _, Message@1} ->
<<"JsonParseError: "/utf8, Message@1/binary>>;
{timeout, Ms} ->
<<<<"Timeout(after="/utf8, (erlang:integer_to_binary(Ms))/binary>>/binary,
"ms)"/utf8>>;
{config_error, Message@2} ->
<<"ConfigError: "/utf8, Message@2/binary>>
end.