Nous.CodeRuntime.Result (nous v0.17.1)

Copy Markdown View Source

What a program produced.

value is the program's return value, already decoded. logs are its output lines in order. error is nil on success, otherwise a Nous.CodeRuntime.Failure.

logs are populated even when error is set. A program that printed six lines and then looped forever until the deadline has told you where it got to, and throwing that away in favour of a bare :timeout is how a debuggable failure becomes a mystery. Providers must stream output eagerly rather than collecting it at the end, or a killed run loses everything it said.

Summary

Functions

A failed result, carrying whatever the program managed to say first.

A successful result.

Whether the program produced a value.

Types

t()

@type t() :: %Nous.CodeRuntime.Result{
  error: Nous.CodeRuntime.Failure.t() | nil,
  logs: [String.t()],
  value: term()
}

Functions

failed(kind, message, logs \\ [])

@spec failed(Nous.CodeRuntime.Failure.kind(), String.t(), [String.t()]) :: t()

A failed result, carrying whatever the program managed to say first.

ok(value, logs \\ [])

@spec ok(term(), [String.t()]) :: t()

A successful result.

success?(result)

@spec success?(t()) :: boolean()

Whether the program produced a value.

Examples

iex> Nous.CodeRuntime.Result.ok(42) |> Nous.CodeRuntime.Result.success?()
true

iex> Nous.CodeRuntime.Result.failed(:timeout, "deadline") |> Nous.CodeRuntime.Result.success?()
false