os.ErrNotExist

The sentinel error Go file functions return, wrapped, when a file or folder does not exist.

In more detail

Test for it with errors.Is(err, os.ErrNotExist), never by comparing message text, which differs between systems. Treat not-exist as an expected case, such as falling back to defaults, and any other error as a real problem.

Example

case errors.Is(err, os.ErrNotExist):
	fmt.Printf("%s: absent\n", path)

Related terms

Taught in

References