method TaskClass.prototype.context
Private
TaskClass.prototype.context(message: string): TaskClass<T, E>

Adds context to a declared failure — anyhow's .context(). Named for what it does, and deliberately NOT expect: Result.expect is Rust's, which PROMOTES a failure to a bug, and one word meaning both "keep this handled" and "crash on this" is the confusion worth spending a rename to avoid. A Failure rethrows as a new Failure with the same code and data (so E, and every switch on code, still hold), message as the context line, and the original chained under cause. A bug passes through untouched: promoting it into the declared tier would hide it from the boundary.

const loadUser = (id: number) => Task(() => ({ name: 'u' + id }));

await loadUser(7).context('route /users/7 needs its user');
// and when loadUser rejects with Failure(NotFound), the await throws:
// Failure(NotFound): route /users/7 needs its user
//   caused by: Failure(NotFound): no user 7

Parameters

message: string

Return Type

Usage

import { TaskClass } from "lib/task/task.ts";