outcome

Types

Alias to Result with Stack as error type.

pub type Outcome(t) =
  Result(t, Stack)

An application error is either a Defect or a Failure. A Defect is an unexpected application error, which shouldn’t be shown to the user. A Failure is an expected error. Context is just information about the place in the application to build a stack trace.

pub type Problem {
  Context(String)
  Defect(String)
  Failure(String)
}

Constructors

  • Context(String)
  • Defect(String)
  • Failure(String)

A stack of problems and context.

pub type Stack {
  Stack(problem: Problem, problems: List(Problem))
}

Constructors

  • Stack(problem: Problem, problems: List(Problem))

Functions

pub fn add_context(
  outcome outcome: Result(a, Stack),
  context context: String,
) -> Result(a, Stack)

Add context to an Outcome

pub fn add_context_to_stack(stack: Stack, value: String) -> Stack
pub fn add_defect_to_stack(stack: Stack, value: String) -> Stack
pub fn add_failure_to_stack(stack: Stack, value: String) -> Stack
pub fn add_to_stack(stack: Stack, new_problem: Problem) -> Stack

Add a Problem to the top of a Stack

pub fn as_defect(
  result: Result(a, Nil),
  e: String,
) -> Result(a, Stack)

Replaces an Problem with a wrapped Defect

pub fn as_failure(
  result: Result(a, Nil),
  e: String,
) -> Result(a, Stack)

Replaces an Problem with a wrapped Failure

pub fn defect(value: String) -> Problem

Wrap a String into a Defect

pub fn error_with_defect(defect: String) -> Result(a, Stack)

Create a Defect wrapped in an Problem

pub fn error_with_failure(failure: String) -> Result(a, Stack)

Create Failure wrapped in an Problem

pub fn failure(value: String) -> Problem

Wrap a String into a Failure

pub fn into_defect(result: Result(a, String)) -> Result(a, Stack)

Convert an Problem into a wrapped Defect

pub fn into_failure(
  result: Result(a, String),
) -> Result(a, Stack)

Convert an Problem into a wrapped Failure

pub fn map_into_defect(
  result: Result(a, b),
  mapper: fn(b) -> String,
) -> Result(a, Stack)

Convert an Problem into a wrapped Defect, by using a mapping function

pub fn new_stack(error: Problem) -> Stack

Create a new Stack with the given Problem

pub fn new_stack_with_defect(failure: String) -> Stack

Create a Defect wrapped in an Stack

pub fn new_stack_with_failure(failure: String) -> Stack

Create a Failure wrapped in an Stack

pub fn pretty_print(stack: Stack) -> String
pub fn stack_to_lines(stack: Stack) -> List(String)
pub fn stack_to_problems(stack: Stack) -> List(Problem)

Get a list of problems for a Stack

pub fn unwrap_failure(stack: Stack, default: String) -> String

Get the failure at the top of the stack. If the top is not a failure, then return the given default. Use this for showing an error message to users.

Search Document