Standard library / os

os.NewSyscallError()

Wraps a non-nil error with the syscall name; returns nil for a nil input. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
func NewSyscallError(syscall string, err error) error

Parameters & Attributes

NameTypeDescription
syscallstringName of the system call.
errerrorUnderlying error.

Return Value

error

Wraps a non-nil error with the syscall name; returns nil for a nil input.

Working Example

Example Snippetgo
package main
import (  "errors"  "fmt"  "os"  "syscall")
func must(e error) {  if e != nil {    panic(e)  }}func main() {  e := os.NewSyscallError("read", syscall.EIO)  fmt.Println(errors.Is(e, syscall.EIO), os.NewSyscallError("read", nil) == nil)}
Go Reference