{"record":{"id":"cb1d69ce0fd2b4be","repo":"siyuan-note/siyuan","slug":"conf-language-1","errorCode":null,"errorMessage":"Conf.Language(1)","messagePattern":"Conf\\.Language\\(1\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":2338,"sourceCode":"\t\tparentID := path.Base(folder)\n\t\tparentTree, loadErr := LoadTreeByBlockID(parentID)\n\t\tif nil != loadErr {\n\t\t\tlogging.LogErrorf(\"get parent tree [%s] failed\", parentID)\n\t\t\treturn nil, ErrBlockNotFound\n\t\t}\n\t\tparentPath := strings.TrimSuffix(parentTree.Path, \".sy\")\n\t\tif parentTree.Box != boxID || cleanBoxDocDir(parentPath) != cleanBoxDocDir(folder) {\n\t\t\tlogging.LogErrorf(\"parent tree [%s] does not match box [%s] and folder [%s]\", parentID, boxID, folder)\n\t\t\treturn nil, ErrBlockNotFound\n\t\t}\n\t\thPath = path.Join(parentTree.HPath, title)\n\t}\n\n\tif depth := strings.Count(p, \"/\"); 7 < depth && !Conf.FileTree.AllowCreateDeeper {\n\t\treturn nil, errors.New(Conf.Language(118))\n\t}\n\tif box.Exist(p) {\n\t\treturn nil, errors.New(Conf.Language(1))\n\t}\n\n\tret = &createDocValidation{\n\t\tbox:     box,\n\t\tpath:    p,\n\t\ttitle:   title,\n\t\thPath:   hPath,\n\t\tid:      util.GetTreeID(p),\n\t\tfolder:  folder,\n\t\tisEmpty: isEmpty,\n\t}\n\treturn\n}\n\nfunc cleanBoxDocDir(p string) string {\n\treturn path.Clean(\"/\" + strings.TrimPrefix(p, \"/\"))\n}\n","sourceCodeStart":2320,"sourceCodeEnd":2356,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file.go#L2320-L2356","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst path = `/${fixedID}`; // reused across retries\nawait fetchPost(\"/api/filetree/createDoc\", { notebook, path, title });\n// after\nconst path = `/${genSyID()}`; // fresh timestamp+random ID per call\nawait fetchPost(\"/api/filetree/createDoc\", { notebook, path, title });","handlingStrategy":"validation","validationCode":"const genSyID = () => {\n  const ts = new Date();\n  const p = n => String(n).padStart(2, \"0\");\n  const stamp = `${String(ts.getFullYear()).slice(2)}${p(ts.getMonth()+1)}${p(ts.getDate())}${p(ts.getHours())}${p(ts.getMinutes())}${p(ts.getSeconds())}`;\n  return `${stamp}-${Math.random().toString(36).slice(2, 9)}`;\n};","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["kernel","create-doc","duplicate","id-collision"],"backgroundTag":"file-already-exists","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}