Standard library / errors
errors.Unwrap()
Calls Unwrap() error if implemented; otherwise returns nil. Does not traverse Unwrap() []error, so use Is or As for joined error trees. Expected stdout: 'true true\n'.
Formal Syntax & Structure
go syntaxgo
func Unwrap(err error) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| err | error | Error to inspect or unwrap. |
Return Value
error
Direct single wrapped error or nil.
Working Example
Example Snippetgo
package main
import ( "errors" "fmt")
func main() { base := errors.New("a") e := fmt.Errorf("wrap: %w", base) fmt.Println(errors.Unwrap(e) == base, errors.Unwrap(errors.Join(base)) == nil)}