mule/rescue

The executor’s rescue/catch analog: run a thunk under an Erlang try/catch and classify abnormal exit reasons the way producer.ex’s DOWN clauses do. Formatting happens in the FFI because raw Erlang terms are unrepresentable in typed Gleam.

Types

pub type Crash {
  Crash(
    kind: exceptions.Kind,
    reason: String,
    stacktrace: List(String),
    raw: RawCrash,
  )
}

Constructors

Classification of a monitored process’s abnormal exit reason, mirroring producer.ex’s DOWN clauses (%TimeoutError{} / :shutdown / {error, stack} / other).

pub type ExitClass {
  TimeoutExit(worker: String, timeout: Int)
  ShutdownExit
  CrashExit(reason: String, stacktrace: List(String))
}

Constructors

  • TimeoutExit(worker: String, timeout: Int)
  • ShutdownExit
  • CrashExit(reason: String, stacktrace: List(String))

The raw {Kind, Reason, Stacktrace} Erlang terms, kept opaque so a caught crash can be re-raised with its original reason and trace.

pub type RawCrash

Values

pub fn classify_exit_reason(reason: dynamic.Dynamic) -> ExitClass
pub fn reraise(crash: RawCrash) -> anything

:erlang.raise(kind, reason, stacktrace) with the original terms.

pub fn rescue(run: fn() -> value) -> Result(value, Crash)

Run run under an Erlang try/catch. Catches raises, throws, and exits raised within the calling process; exit signals (timer:exit_after, process.kill) still terminate the process — those stay on the producer’s monitor-DOWN backstop, exactly as in Elixir.

Search Document