go io_error ai_generated true

open /path/to/file: no such file or directory

ID: go/os-open-no-such-file

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-12-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.13 active
1.14 active
1.15 active

Root Cause

Attempting to open a file that does not exist, often due to a typo in the path or the file being deleted.

generic

中文

尝试打开不存在的文件,通常是由于路径拼写错误或文件已被删除。

Workarounds

  1. 95% success
    Use os.OpenFile with O_RDONLY and check the error.
  2. 85% success
    Use filepath.Abs to resolve the path and verify it.

Dead Ends

Common approaches that don't work:

  1. 50% fail

    There is a race condition between the check and the open.

  2. 60% fail

    This creates an empty file, which may not be desirable.