Standard library / os

os.LinkError.Unwrap()

Returns the underlying error so callers can inspect wrapped errors. Example uses a disposable temporary workspace. Expected stdout: 'true\n'.

Formal Syntax & Structure

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

Return Value

error

Returns the underlying error so callers can inspect wrapped errors.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os")
func check(e error) {  if e != nil {    panic(e)  }}func workspace() func() {  root, e := os.MkdirTemp("", "bytemind-go-")  check(e)  old, e := os.Getwd()  check(e)  check(os.Chdir(root))  return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() {  defer workspace()()  e := &os.LinkError{Err: os.ErrNotExist}  fmt.Println(e.Unwrap() == os.ErrNotExist)}
Go Reference