Standard library / os

os.SyscallError.Unwrap()

Exposes the underlying error, enabling errors.Is and errors.As traversal. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (e *SyscallError) Unwrap() error

Return Value

error

Exposes the underlying error, enabling errors.Is and errors.As traversal.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os"  "syscall")
func must(e error) {  if e != nil {    panic(e)  }}func main() {  e := &os.SyscallError{Syscall: "read", Err: syscall.EIO}  fmt.Println(e.Unwrap() == syscall.EIO)}
Go Reference