Standard library / io/fs

fs.ErrNotExist

Generic missing-file sentinel; inspect via errors.Is rather than text comparison. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
var ErrNotExist error

Working Example

Example Snippetgo
package main
import (  "errors"  "fmt"  "io/fs"  "testing/fstest"  "time")
func tree() fstest.MapFS {  return fstest.MapFS{"a.txt": &fstest.MapFile{Data: []byte("ok"), Mode: 0644, ModTime: time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)}, "sub/b.txt": &fstest.MapFile{Data: []byte("go"), Mode: 0644}}}func main() { _, e := tree().Open("missing"); fmt.Println(errors.Is(e, fs.ErrNotExist)) }
Go Reference