View Source Babel.Trace (Babel v1.0.1)

Represents the evaluation of a Babel.Applicable. Contains the evaluated applicable, the input data, the output result, and any traces of nested Babel.Applicables.

Implements Inspect to render a human-readable version of the information.

To analyze a Babel.Trace - especially one with nested traces - find/2 will be your friend.

Summary

Functions

Recursively checks all nested traces (and this one) against a given spec (or function).

Returns the nested traces which caused the given trace to fail.

Types

@type t() :: t(any(), any())
@type t(output) :: t(any(), output)
@type t(input, output) :: %Babel.Trace{
  babel: Babel.t(input, output),
  input: Babel.data(),
  nested: [t()],
  output: Babel.Step.result(output)
}

Functions

@spec error?(t()) :: boolean()
@spec find(t(), function :: (t() -> boolean())) :: [t()]
@spec find(t(), spec_or_path :: spec | [spec, ...]) :: [t()]
when spec: Babel.t() | Babel.name() | (builtin_name :: atom())

Recursively checks all nested traces (and this one) against a given spec (or function).

Useful for debugging purposes.

Specs

In addition to being able to pass a function find/2 supports some convenient shortcuts:

  • name of a builtin step (e.g. :fetch or :map, see below for a full list)
  • the actual step (e.g. Babel.fetch(["fetched", "path"]))
  • a list of all of the above (incl. functions) to recursively find matching traces (e.g. [:map, :into, :fetch] to find all fetch traces inside of Babel.map(Babel.into(...)))

All builtin step names:

  • :call
  • :cast
  • :const
  • :fail
  • :fetch
  • :flat_map
  • :get
  • :identity
  • :into
  • :map
  • :match
  • :root
  • :then
  • :try

Examples

iex> pipeline = Babel.fetch("list") |> Babel.map(Babel.into(%{some_key: Babel.fetch("some key")}))
iex> data = %{"list" => [%{"some key" => "value1"}, %{"some key" => "value2"}]}
iex> trace = Babel.trace(pipeline, data)
iex> Babel.Trace.find(trace, &Babel.Trace.error?/1)
[]
iex> Babel.Trace.find(trace, :fetch)
[
  Babel.trace(Babel.fetch("list"), data),
  Babel.trace(Babel.fetch("some key"), %{"some key" => "value1"}),
  Babel.trace(Babel.fetch("some key"), %{"some key" => "value2"}),
]
iex> Babel.Trace.find(trace, Babel.fetch("list"))
[
  Babel.trace(Babel.fetch("list"), data)
]
iex> Babel.Trace.find(trace, [:into, :fetch])
[
  Babel.trace(Babel.fetch("some key"), %{"some key" => "value1"}),
  Babel.trace(Babel.fetch("some key"), %{"some key" => "value2"}),
]
Link to this function

matches_spec?(babel, spec)

View Source
Link to this function

new(babel, input, output, nested \\ [])

View Source
@spec new(
  babel :: Babel.t(input, output),
  input :: input | Babel.Context.t(input),
  output :: Babel.Step.result(output),
  nested :: [t()]
) :: t(input, output)
when input: any(), output: any()
@spec ok?(t()) :: boolean()
@spec result(t()) :: {:ok, value :: any()} | {:error, reason :: any()}
@spec root_causes(t()) :: [t()]

Returns the nested traces which caused the given trace to fail.

To be specific it recursively checks all nested traces and collects all error traces which have no nested traces themselves, assuming that this implies that they were the root cause of the failure.