Standard library / os
os.LinkError.Error()
Formats the operation, source, destination and underlying error into human-readable text; avoid parsing it for classification. Example uses a disposable temporary workspace. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (e *LinkError) Error() stringReturn Value
string
Formats the operation, source, destination and underlying error into human-readable text; avoid parsing it for classification.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "strings")
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{Op: "rename", Old: "a", New: "b", Err: os.ErrNotExist} fmt.Println(strings.Contains(e.Error(), "rename a b"))}