{"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":433,"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":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/model/box.go#L415-L451","documentation":"Box.Mkdir creates a single directory level inside a notebook after validateBoxPath. It uses os.Mkdir (not MkdirAll), so an existing directory (EEXIST) is an error like any other; the OS error is wrapped into localized message 6 'Create notebook [%s] folder [%s] failed: %s' and logged.","triggerScenarios":"POST /api/filetree/createDocWithMd or folder-creation paths calling Box.Mkdir for a path whose last segment already exists, contains an OS-illegal character, or sits under a read-only parent.","commonSituations":"Re-running an import script that recreates the same folder; concurrent requests racing to create the same path; folder names with characters the filesystem rejects.","solutions":["Check existence first (Box.Exist / stat) and skip or treat EEXIST as success for idempotent imports","For nested paths, create each level or use the MkdirAll-backed path instead of one-shot Mkdir","Sanitize folder names for the host filesystem and confirm the notebook is not read-only"],"exampleFix":"// before\nbox.Mkdir('imports/2026/notes'); // parent missing -> error\n\n// after\nbox.MkdirAll('imports/2026/notes'); // creates every level","handlingStrategy":"validation","validationCode":"if (!box.Exist(path)) { box.Mkdir(path) } // avoids EEXIST from single-level os.Mkdir","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make imports idempotent: stat before create","Use MkdirAll-backed paths for nested folders","Validate folder names against host-filesystem rules"],"tags":["filesystem","notebook","api"],"backgroundTag":"mkdir-failed","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}