Current section

Files

Jump to
cigogne src cigogne@internal@utils.erl
Raw

src/cigogne@internal@utils.erl

-module(cigogne@internal@utils).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([result_guard/3, describe_decode_error/1, describe_query_error/1, describe_transaction_error/1]).
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 7).
-spec result_guard({ok, ICM} | {error, any()}, ICQ, fun((ICM) -> ICQ)) -> ICQ.
result_guard(Result, Otherwise, Callback) ->
case Result of
{error, _} ->
Otherwise;
{ok, V} ->
Callback(V)
end.
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 46).
-spec describe_decode_error(gleam@dynamic:decode_error()) -> binary().
describe_decode_error(Error) ->
<<<<<<<<<<<<"Expecting : "/utf8, (erlang:element(2, Error))/binary>>/binary,
", Got : "/utf8>>/binary,
(erlang:element(3, Error))/binary>>/binary,
" [at "/utf8>>/binary,
(begin
_pipe = erlang:element(4, Error),
gleam@string:join(_pipe, <<"/"/utf8>>)
end)/binary>>/binary,
"]"/utf8>>.
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 18).
-spec describe_query_error(pog:query_error()) -> binary().
describe_query_error(Error) ->
case Error of
connection_unavailable ->
<<"CONNECTION UNAVAILABLE"/utf8>>;
{constraint_violated, Message, _, _} ->
Message;
{postgresql_error, _, _, Message@1} ->
<<"Postgresql error : "/utf8, Message@1/binary>>;
{unexpected_argument_count, Expected, Got} ->
<<<<<<<<"Expected "/utf8, (gleam@int:to_string(Expected))/binary>>/binary,
" arguments, got "/utf8>>/binary,
(gleam@int:to_string(Got))/binary>>/binary,
" !"/utf8>>;
{unexpected_argument_type, Expected@1, Got@1} ->
<<<<<<<<"Expected argument of type "/utf8, Expected@1/binary>>/binary,
", got "/utf8>>/binary,
Got@1/binary>>/binary,
" !"/utf8>>;
{unexpected_result_type, Errs} ->
<<"Unexpected result type ! \n"/utf8,
(begin
_pipe = gleam@list:map(Errs, fun describe_decode_error/1),
gleam@string:join(_pipe, <<"\n"/utf8>>)
end)/binary>>
end.
-file("/home/runner/work/cigogne/cigogne/src/cigogne/internal/utils.gleam", 38).
-spec describe_transaction_error(pog:transaction_error()) -> binary().
describe_transaction_error(Error) ->
case Error of
{transaction_query_error, Suberror} ->
describe_query_error(Suberror);
{transaction_rolled_back, Message} ->
<<"Transaction rolled back : "/utf8, Message/binary>>
end.