go
io_error
ai_generated
true
错误:mkdir /path/dir:文件已存在
error: mkdir /path/dir: file exists
ID: go/os-file-already-exists
80%修复率
88%置信度
0证据数
2026-08-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
根因分析
尝试创建已存在的目录,而未先检查其是否存在。
English
Attempting to create a directory that already exists, without checking for its existence first.
解决方案
-
98% 成功率 Use os.MkdirAll which does not error if exists
if err := os.MkdirAll(path, 0755); err != nil { return err }
无效尝试
常见但无效的做法:
-
Ignoring error and continuing
40% 失败
May lead to inconsistent state; always handle properly.