Standard library / os

os.LinkError

Reports an error on a two-path operation such as link or rename. Inspect the wrapped cause using errors.Is. Example uses a disposable temporary workspace. Expected stdout: 'true missing new\n'.

Formal Syntax & Structure

go syntaxgo
type LinkError struct { Op string; Old string; New string; Err error }

Working Example

Example Snippetgo
package main
import (  "errors"  "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.Rename("missing", "new")  var p *os.LinkError  fmt.Println(errors.As(e, &p), p.Old, p.New)}
Go Reference