runtime

package
v0.6.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPanicRecovery         = errors.New("cannot safecall function: recovered from a panic")
	ErrInvalidFunction       = errors.New("cannot safecall function: first argument is not a function")
	ErrIncorrectArguments    = errors.New("cannot safecall function: number of arguments does not match function's input arity")
	ErrMoreThanTwoReturns    = errors.New("cannot safecall function: function returns more than two values")
	ErrInvalidLastReturnType = errors.New("cannot safecall function: invalid last return type (expected error)")
)

Functions

func SafeCall

func SafeCall(fn any, args ...any) (result any, err error)

SafeCall safely calls a function using reflection. It handles potential panics by recovering and returning an error. The function `fn` is expected to be a function, and `args` are the arguments to pass to that function. It returns the result of the function call (if any) and an error if one occurred during the call or if a panic was recovered.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL