{"record":{"id":"4b555cbde9fc8628","repo":"siyuan-note/siyuan","slug":"create-notebook-s-folder-s-failed-s","errorCode":null,"errorMessage":"Create notebook [%s] folder [%s] failed: %s","messagePattern":"Create notebook \\[(.+?)\\] folder \\[(.+?)\\] failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/box.go","lineNumber":432,"sourceCode":"\t}\n\treturn\n}\n\nfunc (box *Box) Exist(p string) bool {\n\tif _, err := box.validateBoxPath(p); err != nil {\n\t\treturn false\n\t}\n\treturn filelock.IsExist(filepath.Join(util.DataDir, box.ID, p))\n}\n\nfunc (box *Box) Mkdir(path string) error {\n\tif _, err := box.validateBoxPath(path); err != nil {\n\t\treturn err\n\t}\n\tif err := os.Mkdir(filepath.Join(util.DataDir, box.ID, path), 0755); err != nil {\n\t\tmsg := fmt.Sprintf(Conf.Language(6), box.Name, path, err)\n\t\tlogging.LogErrorf(\"mkdir [path=%s] in box [%s] failed: %s\", path, box.ID, err)\n\t\treturn errors.New(msg)\n\t}\n\tIncSync()\n\treturn nil\n}\n\nfunc (box *Box) MkdirAll(path string) error {\n\tif _, err := box.validateBoxPath(path); err != nil {\n\t\treturn err\n\t}\n\tif err := os.MkdirAll(filepath.Join(util.DataDir, box.ID, path), 0755); err != nil {\n\t\tmsg := fmt.Sprintf(Conf.Language(6), box.Name, path, err)\n\t\tlogging.LogErrorf(\"mkdir all [path=%s] in box [%s] failed: %s\", path, box.ID, err)\n\t\treturn errors.New(msg)\n\t}\n\tIncSync()\n\treturn nil\n}\n","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/box.go#L414-L450","documentation":"In Box.Mkdir, after validateBoxPath, os.Mkdir(<DataDir>/<boxID>/path, 0755) is attempted; on failure it logs and returns errors.New(fmt.Sprintf(Conf.Language(6), box.Name, path, err)) — 'Create notebook [%s] folder [%s] failed: %s'. Mkdir is non-recursive: it requires the parent to exist and the target to not exist.","triggerScenarios":"A single-level folder creation inside a notebook (filetree/mkdir-style operations) where the parent directory is missing, the target already exists, permissions are insufficient, or the path is on a read-only volume.","commonSituations":"Creating a subfolder under a path whose parent was removed; recreating a folder that already exists; race with another client that created it first; read-only data dir.","solutions":["Use Box.MkdirAll (recursive) when intermediate directories may not exist.","Check Box.Exist(path) first and skip if the folder is already there.","Confirm write permission on the notebook's data directory."],"exampleFix":"// before\nif err := box.Mkdir(path); err != nil { return err }\n\n// after: create parents and tolerate an existing folder\nif box.Exist(path) { return nil }\nif err := box.MkdirAll(path); err != nil { return err }","handlingStrategy":"validation","validationCode":"// Use the recursive variant when the parent may not exist.\nif !box.Exist(path) {\n    return box.MkdirAll(path)\n}","typeGuard":null,"tryCatchPattern":"// Tolerate 'already exists' as success.\nif err := box.Mkdir(path); err != nil && box.Exist(path) { return nil } else if err != nil { return err }","preventionTips":["Existence-check before Mkdir to avoid races.","Prefer MkdirAll for arbitrary nested paths."],"tags":["filesystem","notebook","mkdir"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}