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) error

Parameters & Attributes

NameTypeDescription
formatstringFormat string containing literal text and formatting or scanning directives.
a...anyValues 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))}
Go Reference