Documentation
¶
Overview ¶
Package must provides panic-on-error helpers for enforcing invariants.
Use must for startup-time configuration, code generation, tests, and programmer-error invariants — cases where failure means a bug or misconfiguration, not a recoverable runtime condition.
Do not use must for user input, expected I/O failures, or exported library APIs unless panic semantics are explicitly part of the contract.
BeNil, Get, and Get2 panic with the original error value, preserving error chains for errors.Is/errors.As after recovery. NonEmptyEnv panics with a descriptive error wrapping ErrEnvUnset or ErrEnvEmpty for machine-checkable classification after recovery.
From panics immediately if given a nil function, wrapping ErrNilFunction.
For recoverable error handling instead of panics, see [rslt.Result].
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEnvEmpty = errors.New("environment variable empty")
ErrEnvEmpty indicates the environment variable is set but empty.
var ErrEnvUnset = errors.New("environment variable unset")
ErrEnvUnset indicates the environment variable is not set.
var ErrNilFunction = errors.New("nil function")
ErrNilFunction indicates a nil function was passed where one is required.
Functions ¶
func BeNil ¶
func BeNil(err error)
BeNil panics if err is not nil. The panic value is err itself, preserving error chains for errors.Is/errors.As after recovery.
func From ¶ added in v0.60.0
From returns the "must" version of fn. fn must be a single-argument function. Panics immediately if fn is nil, wrapping ErrNilFunction.
Example ¶
package main
import (
"fmt"
"strconv"
"github.com/binaryphile/fluentfp/must"
"github.com/binaryphile/fluentfp/slice"
)
func main() {
// mustAtoi wraps strconv.Atoi to panic on parse error.
mustAtoi := must.From(strconv.Atoi)
nums := slice.From([]string{"1", "2", "3"}).ToInt(mustAtoi)
fmt.Println(nums)
}
Output: [1 2 3]
func Get ¶
Get returns the value of a (value, error) pair, or panics if error is non-nil. The panic value is the original error, preserving error chains for errors.Is/errors.As after recovery.
func Get2 ¶
Get2 returns the values of a (value, value, error) triple, or panics if error is non-nil. The panic value is the original error, preserving error chains for errors.Is/errors.As after recovery.
func NonEmptyEnv ¶ added in v0.41.0
NonEmptyEnv returns the value of the environment variable named by key. It panics if the variable is unset or empty. The panic value wraps ErrEnvUnset or ErrEnvEmpty for errors.Is matching.
Types ¶
This section is empty.