Skip to content

Commit

Permalink
Make the Elixir harness not error.
Browse files Browse the repository at this point in the history
Returning `errored` responses is only allowed for `run` requests, and
adding additional properties is not allowed.

Refs: #100, which is the issue for adding support for testing output
      formats, though we separately would like to add support for collecting
      output messages first even if we don't yet test it, but right now you
      cannot add additional properties.
  • Loading branch information
Julian committed Jan 14, 2025
1 parent 9a8ac97 commit 58b22ce
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions implementations/elixir-jsv/lib/bowtie_jsv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ defmodule BowtieJSV do

{:reply, %{seq: tseq, results: results}, state}
rescue
e -> {:reply, errored(e, __STACKTRACE__, %{seq: tseq}), state}
e -> {:reply, %{
errored: true,
seq: tseq,
message: Exception.message(e),
traceback: Exception.format_stacktrace(__STACKTRACE__),
}, state}
end

defp build_schema(raw_schema, registry, state) do
Expand All @@ -74,10 +79,8 @@ defmodule BowtieJSV do

case JSV.validate(data, root) do
{:ok, _} -> %{valid: true}
{:error, verr} -> %{valid: false, output: JSV.normalize_error(verr)}
{:error, _} -> %{valid: false}
end
rescue
e -> errored(e, __STACKTRACE__)
end

defp start_response do
Expand All @@ -100,16 +103,4 @@ defmodule BowtieJSV do
{:ok, jsv_vsn} = :application.get_key(:jsv, :vsn)
List.to_string(jsv_vsn)
end

defp errored(e, stacktrace, additional_data \\ %{}) do
errorred_payload = %{
errored: true,
context: %{
message: Exception.message(e),
traceback: Exception.format_stacktrace(stacktrace)
}
}

Map.merge(errorred_payload, additional_data)
end
end

0 comments on commit 58b22ce

Please sign in to comment.