Standard library / fmt
fmt.Errorf()
Creates a formatted error. A %w operand wraps an error; multiple %w verbs produce an error with Unwrap() []error. Use %v when wrapping is not part of the intended API. Expected stdout: 'load: missing true\n'.
Formal Syntax & Structure
go syntaxgo
func Errorf(format string, a ...any) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| format | string | Format string containing literal text and formatting or scanning directives. |
| a | ...any | Values consumed by formatting; may be empty. |
Return Value
error
Formatted error, potentially wrapping operands.
Working Example
Example Snippetgo
package main
import ( "errors" "fmt")
func main() { base := errors.New("missing") e := fmt.Errorf("load: %w", base) fmt.Println(e, errors.Is(e, base))}