siyuan-note/siyuan · error
Conf.Language(1)
Error message
Conf.Language(1)
What it means
After depth validation, validateCreateDoc calls box.Exist(p); if a document already exists at the exact target path it returns errors.New(Conf.Language(1)), "Duplicated filename". Document paths in SiYuan embed a unique ID, so a duplicate means the client is reusing an existing doc's path/ID rather than generating a fresh one.
Solutions
- Generate a fresh unique doc ID (yyMMddHHmmss + random suffix) for each create instead of reusing paths.
- Check existence first via /api/filetree/getHPathByPath or box.Exist-equivalent before creating.
- If the doc should not be duplicated, remove the prior one or open/rename it instead of creating.
- Make retry logic idempotent: on 'Duplicated filename', treat the doc as already created.
Example fix
// before
const path = `/${fixedID}`; // reused across retries
await fetchPost("/api/filetree/createDoc", { notebook, path, title });
// after
const path = `/${genSyID()}`; // fresh timestamp+random ID per call
await fetchPost("/api/filetree/createDoc", { notebook, path, title }); Defensive patterns
Strategy: validation
Validate before calling
const genSyID = () => {
const ts = new Date();
const p = n => String(n).padStart(2, "0");
const stamp = `${String(ts.getFullYear()).slice(2)}${p(ts.getMonth()+1)}${p(ts.getDate())}${p(ts.getHours())}${p(ts.getMinutes())}${p(ts.getSeconds())}`;
return `${stamp}-${Math.random().toString(36).slice(2, 9)}`;
}; Prevention
- Generate a fresh doc ID for every createDoc call; never reuse paths.
- Make retries idempotent: on 'Duplicated filename', treat as success.
- Check existence (getHPathByPath) when creation must be unique-per-title.
When it happens
Trigger: Calling /api/filetree/createDoc with a path whose <timestamp>-<random> ID basename already exists in the notebook; retrying a createDoc request that already succeeded; a client ID generator producing collisions or reusing cached IDs.
Common situations: Retry logic without idempotency that replays a successful create; scripts that hardcode doc IDs in templates; importing the same content twice; clock-free ID generators producing identical timestamps with identical random parts.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/cb1d69ce0fd2b4be.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/file.go:2338
parentID := path.Base(folder)
parentTree, loadErr := LoadTreeByBlockID(parentID)
if nil != loadErr {
logging.LogErrorf("get parent tree [%s] failed", parentID)
return nil, ErrBlockNotFound
}
parentPath := strings.TrimSuffix(parentTree.Path, ".sy")
if parentTree.Box != boxID || cleanBoxDocDir(parentPath) != cleanBoxDocDir(folder) {
logging.LogErrorf("parent tree [%s] does not match box [%s] and folder [%s]", parentID, boxID, folder)
return nil, ErrBlockNotFound
}
hPath = path.Join(parentTree.HPath, title)
}
if depth := strings.Count(p, "/"); 7 < depth && !Conf.FileTree.AllowCreateDeeper {
return nil, errors.New(Conf.Language(118))
}
if box.Exist(p) {
return nil, errors.New(Conf.Language(1))
}
ret = &createDocValidation{
box: box,
path: p,
title: title,
hPath: hPath,
id: util.GetTreeID(p),
folder: folder,
isEmpty: isEmpty,
}
return
}
func cleanBoxDocDir(p string) string {
return path.Clean("/" + strings.TrimPrefix(p, "/"))
}
View on GitHub (pinned to 9f775e8a12)