{"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":2320,"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":2302,"sourceCodeEnd":2338,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/file.go#L2302-L2338","documentation":"After depth validation, validateCreateDoc checks box.Exist(p); if the target path already exists in the notebook it returns errors.New(Conf.Language(1)): \"Duplicated filename\". Document paths in SiYuan must be unique within a notebook, so creating a doc at an occupied path is rejected before any file write.","triggerScenarios":"POST /api/filetree/createDocWithMd or createDoc with a path equal to an existing document's path in that notebook (same ID/name base).","commonSituations":"Retry scripts re-running after a partial failure (doc already created on first run); imports run twice without cleanup; race conditions where two clients create the same-named doc concurrently; generating IDs deterministically so collisions occur.","solutions":["Check existence first via /api/filetree/getHPathByPath or /api/filetree/docExists... and reuse/rename if occupied","Generate a fresh unique ID for the path (via /api/filetree/getID) before creating","Append a distinguishing suffix (timestamp) to the title/path on retry","Wrap creation in logic that treats this error as 'already created' and continues"],"exampleFix":"// before\nawait fetchPost('/api/filetree/createDocWithMd', {notebook, path: fixedPath, markdown});\n// after\nconst exists = await fetchPost('/api/filetree/getHPathByPath', {notebook, path: fixedPath});\nconst path = exists.code === 0 ? fixedPath + '-' + Date.now() : fixedPath;\nawait fetchPost('/api/filetree/createDocWithMd', {notebook, path, markdown});","handlingStrategy":"validation","validationCode":"async function pathIsFree(notebook, p) {\n  const r = await fetchPost('/api/filetree/getHPathByPath', {notebook, path: p});\n  return r.code !== 0; // non-zero means not found, i.e. free\n}","typeGuard":null,"tryCatchPattern":"try {\n  await fetchPost('/api/filetree/createDocWithMd', {notebook, path, markdown});\n} catch (e) {\n  if (String(e).includes('Duplicated filename')) {\n    // treat as already-created, or create with a fresh unique ID\n  }\n}","preventionTips":["Always generate fresh IDs for new doc paths","Make create operations idempotent: check existence before creating","Avoid re-running import scripts without cleanup"],"tags":["siyuan","kernel","create-doc","duplicate","uniqueness"],"backgroundTag":"file-already-exists","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}