Packages
caffeine_lang
5.1.1
6.3.1
6.3.0
6.2.2
6.2.1
6.2.0
6.1.2
6.1.1
6.1.0
6.0.0
5.6.0
5.5.0
5.4.4
5.4.3
5.4.2
5.4.1
5.4.0
5.3.0
5.2.0
5.1.1
5.1.0
5.0.12
5.0.11
5.0.10
5.0.8
5.0.7
5.0.6
5.0.5
5.0.4
5.0.1
5.0.0
4.10.0
4.9.0
4.8.3
4.8.2
4.8.1
4.8.0
4.7.9
4.7.8
4.7.7
4.7.6
4.7.5
4.6.7
4.6.6
4.6.5
4.6.4
4.6.3
4.6.2
4.6.0
4.5.1
4.5.0
4.4.4
4.4.3
4.4.1
4.4.0
4.3.7
4.3.6
3.0.6
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.0.2
1.0.1
0.1.0
0.0.24
0.0.23
0.0.22
0.0.21
0.0.20
0.0.19
0.0.18
0.0.17
0.0.16
0.0.15
0.0.14
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.2
0.0.1
A compiler for generating reliability artifacts from service expectation definitions.
Current section
Files
Jump to
Current section
Files
src/caffeine_lang@errors.erl
-module(caffeine_lang@errors).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/caffeine_lang/errors.gleam").
-export([empty_context/0, frontend_parse_error/1, frontend_validation_error/1, linker_value_validation_error/1, linker_duplicate_error/1, linker_parse_error/1, linker_vendor_resolution_error/1, semantic_analysis_template_parse_error/1, semantic_analysis_template_resolution_error/1, semantic_analysis_dependency_validation_error/1, generator_slo_query_resolution_error/1, generator_terraform_resolution_error/2, cql_resolver_error/1, cql_parser_error/1, error_code_to_string/1, error_code_for/1, error_context/1, prefix_error/2, to_list/1, to_message/1, from_results/1, format_validation_error_message/3]).
-export_type([error_context/0, source_location/0, compilation_error/0, error_code/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 error_context() :: {error_context,
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(source_location()),
gleam@option:option(binary())}.
-type source_location() :: {source_location,
integer(),
integer(),
gleam@option:option(integer())}.
-type compilation_error() :: {frontend_parse_error, binary(), error_context()} |
{frontend_validation_error, binary(), error_context()} |
{linker_value_validation_error, binary(), error_context()} |
{linker_duplicate_error, binary(), error_context()} |
{linker_parse_error, binary(), error_context()} |
{linker_vendor_resolution_error, binary(), error_context()} |
{semantic_analysis_template_parse_error, binary(), error_context()} |
{semantic_analysis_template_resolution_error, binary(), error_context()} |
{semantic_analysis_dependency_validation_error, binary(), error_context()} |
{generator_slo_query_resolution_error, binary(), error_context()} |
{generator_terraform_resolution_error, binary(), binary(), error_context()} |
{c_q_l_resolver_error, binary(), error_context()} |
{c_q_l_parser_error, binary(), error_context()} |
{compilation_errors, list(compilation_error())}.
-type error_code() :: {error_code, binary(), integer()}.
-file("src/caffeine_lang/errors.gleam", 26).
?DOC(" Returns an ErrorContext with all fields set to None.\n").
-spec empty_context() -> error_context().
empty_context() ->
{error_context, none, none, none, none, none}.
-file("src/caffeine_lang/errors.gleam", 69).
?DOC(" Creates a FrontendParseError with empty context.\n").
-spec frontend_parse_error(binary()) -> compilation_error().
frontend_parse_error(Msg) ->
{frontend_parse_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 74).
?DOC(" Creates a FrontendValidationError with empty context.\n").
-spec frontend_validation_error(binary()) -> compilation_error().
frontend_validation_error(Msg) ->
{frontend_validation_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 79).
?DOC(" Creates a LinkerValueValidationError with empty context.\n").
-spec linker_value_validation_error(binary()) -> compilation_error().
linker_value_validation_error(Msg) ->
{linker_value_validation_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 84).
?DOC(" Creates a LinkerDuplicateError with empty context.\n").
-spec linker_duplicate_error(binary()) -> compilation_error().
linker_duplicate_error(Msg) ->
{linker_duplicate_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 89).
?DOC(" Creates a LinkerParseError with empty context.\n").
-spec linker_parse_error(binary()) -> compilation_error().
linker_parse_error(Msg) ->
{linker_parse_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 94).
?DOC(" Creates a LinkerVendorResolutionError with empty context.\n").
-spec linker_vendor_resolution_error(binary()) -> compilation_error().
linker_vendor_resolution_error(Msg) ->
{linker_vendor_resolution_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 99).
?DOC(" Creates a SemanticAnalysisTemplateParseError with empty context.\n").
-spec semantic_analysis_template_parse_error(binary()) -> compilation_error().
semantic_analysis_template_parse_error(Msg) ->
{semantic_analysis_template_parse_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 106).
?DOC(" Creates a SemanticAnalysisTemplateResolutionError with empty context.\n").
-spec semantic_analysis_template_resolution_error(binary()) -> compilation_error().
semantic_analysis_template_resolution_error(Msg) ->
{semantic_analysis_template_resolution_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 113).
?DOC(" Creates a SemanticAnalysisDependencyValidationError with empty context.\n").
-spec semantic_analysis_dependency_validation_error(binary()) -> compilation_error().
semantic_analysis_dependency_validation_error(Msg) ->
{semantic_analysis_dependency_validation_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 120).
?DOC(" Creates a GeneratorSloQueryResolutionError with empty context.\n").
-spec generator_slo_query_resolution_error(binary()) -> compilation_error().
generator_slo_query_resolution_error(Msg) ->
{generator_slo_query_resolution_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 125).
?DOC(" Creates a GeneratorTerraformResolutionError with empty context.\n").
-spec generator_terraform_resolution_error(binary(), binary()) -> compilation_error().
generator_terraform_resolution_error(Vendor, Msg) ->
{generator_terraform_resolution_error, Vendor, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 133).
?DOC(" Creates a CQLResolverError with empty context.\n").
-spec cql_resolver_error(binary()) -> compilation_error().
cql_resolver_error(Msg) ->
{c_q_l_resolver_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 138).
?DOC(" Creates a CQLParserError with empty context.\n").
-spec cql_parser_error(binary()) -> compilation_error().
cql_parser_error(Msg) ->
{c_q_l_parser_error, Msg, empty_context()}.
-file("src/caffeine_lang/errors.gleam", 150).
?DOC(" Converts an ErrorCode to its display string (e.g., \"E103\").\n").
-spec error_code_to_string(error_code()) -> binary().
error_code_to_string(Code) ->
S = erlang:integer_to_binary(erlang:element(3, Code)),
Padding = 3 - string:length(S),
case Padding > 0 of
true ->
<<<<"E"/utf8, (gleam@string:repeat(<<"0"/utf8>>, Padding))/binary>>/binary,
S/binary>>;
false ->
<<"E"/utf8, S/binary>>
end.
-file("src/caffeine_lang/errors.gleam", 181).
?DOC(" Maps a vendor string to its codegen error code.\n").
-spec vendor_to_error_code(binary()) -> error_code().
vendor_to_error_code(Vendor) ->
case Vendor of
V when V =:= <<"datadog"/utf8>> ->
{error_code, <<"codegen"/utf8>>, 502};
V@1 when V@1 =:= <<"honeycomb"/utf8>> ->
{error_code, <<"codegen"/utf8>>, 503};
V@2 when V@2 =:= <<"dynatrace"/utf8>> ->
{error_code, <<"codegen"/utf8>>, 504};
V@3 when V@3 =:= <<"newrelic"/utf8>> ->
{error_code, <<"codegen"/utf8>>, 505};
_ ->
{error_code, <<"codegen"/utf8>>, 500}
end.
-file("src/caffeine_lang/errors.gleam", 160).
?DOC(" Assigns an error code based on the CompilationError variant.\n").
-spec error_code_for(compilation_error()) -> error_code().
error_code_for(Error) ->
case Error of
{frontend_parse_error, _, _} ->
{error_code, <<"parse"/utf8>>, 100};
{frontend_validation_error, _, _} ->
{error_code, <<"validation"/utf8>>, 200};
{linker_value_validation_error, _, _} ->
{error_code, <<"linker"/utf8>>, 302};
{linker_duplicate_error, _, _} ->
{error_code, <<"linker"/utf8>>, 303};
{linker_parse_error, _, _} ->
{error_code, <<"linker"/utf8>>, 301};
{linker_vendor_resolution_error, _, _} ->
{error_code, <<"linker"/utf8>>, 304};
{semantic_analysis_template_parse_error, _, _} ->
{error_code, <<"semantic"/utf8>>, 402};
{semantic_analysis_template_resolution_error, _, _} ->
{error_code, <<"semantic"/utf8>>, 403};
{semantic_analysis_dependency_validation_error, _, _} ->
{error_code, <<"semantic"/utf8>>, 404};
{generator_slo_query_resolution_error, _, _} ->
{error_code, <<"codegen"/utf8>>, 501};
{generator_terraform_resolution_error, Vendor, _, _} ->
vendor_to_error_code(Vendor);
{c_q_l_resolver_error, _, _} ->
{error_code, <<"cql"/utf8>>, 601};
{c_q_l_parser_error, _, _} ->
{error_code, <<"cql"/utf8>>, 602};
{compilation_errors, _} ->
{error_code, <<"multiple"/utf8>>, 0}
end.
-file("src/caffeine_lang/errors.gleam", 193).
?DOC(false).
-spec error_context(compilation_error()) -> error_context().
error_context(Error) ->
case Error of
{frontend_parse_error, _, Context} ->
Context;
{frontend_validation_error, _, Context@1} ->
Context@1;
{linker_value_validation_error, _, Context@2} ->
Context@2;
{linker_duplicate_error, _, Context@3} ->
Context@3;
{linker_parse_error, _, Context@4} ->
Context@4;
{linker_vendor_resolution_error, _, Context@5} ->
Context@5;
{semantic_analysis_template_parse_error, _, Context@6} ->
Context@6;
{semantic_analysis_template_resolution_error, _, Context@7} ->
Context@7;
{semantic_analysis_dependency_validation_error, _, Context@8} ->
Context@8;
{generator_slo_query_resolution_error, _, Context@9} ->
Context@9;
{generator_terraform_resolution_error, _, _, Context@10} ->
Context@10;
{c_q_l_resolver_error, _, Context@11} ->
Context@11;
{c_q_l_parser_error, _, Context@12} ->
Context@12;
{compilation_errors, _} ->
empty_context()
end.
-file("src/caffeine_lang/errors.gleam", 293).
?DOC(" Sets the identifier field on an ErrorContext, preserving existing value if already set.\n").
-spec set_context_identifier(error_context(), binary()) -> error_context().
set_context_identifier(Context, Identifier) ->
case erlang:element(2, Context) of
{some, _} ->
Context;
none ->
{error_context,
{some, Identifier},
erlang:element(3, Context),
erlang:element(4, Context),
erlang:element(5, Context),
erlang:element(6, Context)}
end.
-file("src/caffeine_lang/errors.gleam", 215).
?DOC(false).
-spec prefix_error(compilation_error(), binary()) -> compilation_error().
prefix_error(Error, Identifier) ->
Prefix = <<Identifier/binary, " - "/utf8>>,
case Error of
{frontend_parse_error, Msg, Context} ->
{frontend_parse_error,
<<Prefix/binary, Msg/binary>>,
set_context_identifier(Context, Identifier)};
{frontend_validation_error, Msg@1, Context@1} ->
{frontend_validation_error,
<<Prefix/binary, Msg@1/binary>>,
set_context_identifier(Context@1, Identifier)};
{linker_value_validation_error, Msg@2, Context@2} ->
{linker_value_validation_error,
<<Prefix/binary, Msg@2/binary>>,
set_context_identifier(Context@2, Identifier)};
{linker_duplicate_error, Msg@3, Context@3} ->
{linker_duplicate_error,
<<Prefix/binary, Msg@3/binary>>,
set_context_identifier(Context@3, Identifier)};
{linker_parse_error, Msg@4, Context@4} ->
{linker_parse_error,
<<Prefix/binary, Msg@4/binary>>,
set_context_identifier(Context@4, Identifier)};
{linker_vendor_resolution_error, Msg@5, Context@5} ->
{linker_vendor_resolution_error,
<<Prefix/binary, Msg@5/binary>>,
set_context_identifier(Context@5, Identifier)};
{semantic_analysis_template_parse_error, Msg@6, Context@6} ->
{semantic_analysis_template_parse_error,
<<Prefix/binary, Msg@6/binary>>,
set_context_identifier(Context@6, Identifier)};
{semantic_analysis_template_resolution_error, Msg@7, Context@7} ->
{semantic_analysis_template_resolution_error,
<<Prefix/binary, Msg@7/binary>>,
set_context_identifier(Context@7, Identifier)};
{semantic_analysis_dependency_validation_error, Msg@8, Context@8} ->
{semantic_analysis_dependency_validation_error,
<<Prefix/binary, Msg@8/binary>>,
set_context_identifier(Context@8, Identifier)};
{generator_slo_query_resolution_error, Msg@9, Context@9} ->
{generator_slo_query_resolution_error,
<<Prefix/binary, Msg@9/binary>>,
set_context_identifier(Context@9, Identifier)};
{generator_terraform_resolution_error, Vendor, Msg@10, Context@10} ->
{generator_terraform_resolution_error,
Vendor,
<<Prefix/binary, Msg@10/binary>>,
set_context_identifier(Context@10, Identifier)};
{c_q_l_resolver_error, Msg@11, Context@11} ->
{c_q_l_resolver_error,
<<Prefix/binary, Msg@11/binary>>,
set_context_identifier(Context@11, Identifier)};
{c_q_l_parser_error, Msg@12, Context@12} ->
{c_q_l_parser_error,
<<Prefix/binary, Msg@12/binary>>,
set_context_identifier(Context@12, Identifier)};
{compilation_errors, Errors} ->
{compilation_errors,
gleam@list:map(
Errors,
fun(_capture) -> prefix_error(_capture, Identifier) end
)}
end.
-file("src/caffeine_lang/errors.gleam", 306).
?DOC(false).
-spec to_list(compilation_error()) -> list(compilation_error()).
to_list(Error) ->
case Error of
{compilation_errors, Errors} ->
gleam@list:flat_map(Errors, fun to_list/1);
_ ->
[Error]
end.
-file("src/caffeine_lang/errors.gleam", 316).
?DOC(false).
-spec to_message(compilation_error()) -> binary().
to_message(Error) ->
case Error of
{compilation_errors, Errors} ->
_pipe = Errors,
_pipe@1 = gleam@list:flat_map(_pipe, fun to_list/1),
_pipe@2 = gleam@list:map(_pipe@1, fun to_message/1),
gleam@string:join(_pipe@2, <<"\n"/utf8>>);
{frontend_parse_error, Msg, _} ->
Msg;
{frontend_validation_error, Msg@1, _} ->
Msg@1;
{linker_value_validation_error, Msg@2, _} ->
Msg@2;
{linker_duplicate_error, Msg@3, _} ->
Msg@3;
{linker_parse_error, Msg@4, _} ->
Msg@4;
{linker_vendor_resolution_error, Msg@5, _} ->
Msg@5;
{semantic_analysis_template_parse_error, Msg@6, _} ->
Msg@6;
{semantic_analysis_template_resolution_error, Msg@7, _} ->
Msg@7;
{semantic_analysis_dependency_validation_error, Msg@8, _} ->
Msg@8;
{generator_slo_query_resolution_error, Msg@9, _} ->
Msg@9;
{generator_terraform_resolution_error, _, Msg@10, _} ->
Msg@10;
{c_q_l_resolver_error, Msg@11, _} ->
Msg@11;
{c_q_l_parser_error, Msg@12, _} ->
Msg@12
end.
-file("src/caffeine_lang/errors.gleam", 353).
-spec partition_results(
list({ok, FZJ} | {error, compilation_error()}),
list(FZJ),
list(compilation_error())
) -> {list(FZJ), list(compilation_error())}.
partition_results(Results, Successes, Failures) ->
case Results of
[] ->
{Successes, Failures};
[{ok, Val} | Rest] ->
partition_results(Rest, [Val | Successes], Failures);
[{error, Err} | Rest@1] ->
partition_results(Rest@1, Successes, [Err | Failures])
end.
-file("src/caffeine_lang/errors.gleam", 342).
?DOC(false).
-spec from_results(list({ok, FZC} | {error, compilation_error()})) -> {ok,
list(FZC)} |
{error, compilation_error()}.
from_results(Results) ->
{Successes, Failures} = partition_results(Results, [], []),
case Failures of
[] ->
{ok, lists:reverse(Successes)};
[Single] ->
{error, Single};
Multiple ->
{error, {compilation_errors, lists:reverse(Multiple)}}
end.
-file("src/caffeine_lang/errors.gleam", 367).
?DOC(" Normalizes type names across targets (JS uses \"Array\", Erlang uses \"List\").\n").
-spec normalize_type_name(binary()) -> binary().
normalize_type_name(Name) ->
case Name of
<<"Array"/utf8>> ->
<<"List"/utf8>>;
Other ->
Other
end.
-file("src/caffeine_lang/errors.gleam", 376).
?DOC(false).
-spec format_validation_error_message(
list(caffeine_lang@types:validation_error()),
gleam@option:option(binary()),
gleam@option:option(caffeine_lang@value:value())
) -> binary().
format_validation_error_message(Errors, Type_key_identifier, Val) ->
Value_part = case Val of
{some, V} ->
<<<<" value ("/utf8,
(caffeine_lang@value:to_preview_string(V))/binary>>/binary,
")"/utf8>>;
none ->
<<""/utf8>>
end,
_pipe = Errors,
_pipe@2 = gleam@list:map(
_pipe,
fun(Error) ->
<<<<<<<<<<<<<<<<"expected ("/utf8,
(erlang:element(2, Error))/binary>>/binary,
") received ("/utf8>>/binary,
(normalize_type_name(
erlang:element(3, Error)
))/binary>>/binary,
")"/utf8>>/binary,
Value_part/binary>>/binary,
" for ("/utf8>>/binary,
((case {begin
_pipe@1 = erlang:element(4, Error),
gleam@string:join(_pipe@1, <<"."/utf8>>)
end,
Type_key_identifier} of
{<<""/utf8>>, none} ->
<<"Unknown"/utf8>>;
{Path, none} ->
Path;
{<<""/utf8>>, {some, Val@1}} ->
Val@1;
{Path@1, {some, Val@2}} ->
<<<<Val@2/binary, "."/utf8>>/binary, Path@1/binary>>
end))/binary>>/binary,
")"/utf8>>
end
),
gleam@string:join(_pipe@2, <<", "/utf8>>).