go io_error ai_generated true

error: mkdir /path/dir: file exists

ID: go/os-file-already-exists

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2026-08-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active
1.21 active

Root Cause

Attempting to create a directory that already exists, without checking for its existence first.

generic

中文

尝试创建已存在的目录,而未先检查其是否存在。

Workarounds

  1. 98% success Use os.MkdirAll which does not error if exists
    if err := os.MkdirAll(path, 0755); err != nil { return err }

Dead Ends

Common approaches that don't work:

  1. Ignoring error and continuing 40% fail

    May lead to inconsistent state; always handle properly.