{"record":{"id":"0c1b3457c7cb1d42","repo":"siyuan-note/siyuan","slug":"create-ai-editor-actions-directory-failed-w","errorCode":null,"errorMessage":"create AI editor actions directory failed: %w","messagePattern":"create AI editor actions directory failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/ai_editor.go","lineNumber":193,"sourceCode":"\t\t\treturn nil, errors.New(\"invalid AI editor action data\")\n\t\t}\n\t\tif _, ok := ids[action.ID]; ok {\n\t\t\treturn nil, fmt.Errorf(\"duplicate AI editor action ID [%s]\", action.ID)\n\t\t}\n\t\tids[action.ID] = struct{}{}\n\t}\n\treturn ret, nil\n}\n\nfunc saveAIEditorActions(data *aiEditorActionsData) (err error) {\n\tdata.Version = aiEditorActionsVersion\n\tif data.Actions == nil {\n\t\tdata.Actions = []*AIEditorAction{}\n\t}\n\n\tdirPath := filepath.Dir(aiEditorActionsPath())\n\tif err = os.MkdirAll(dirPath, 0755); err != nil {\n\t\treturn fmt.Errorf(\"create AI editor actions directory failed: %w\", err)\n\t}\n\tbytes, err := gulu.JSON.MarshalIndentJSON(data, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshal AI editor actions failed: %w\", err)\n\t}\n\tif err = filelock.WriteFile(aiEditorActionsPath(), bytes); err != nil {\n\t\treturn fmt.Errorf(\"write AI editor actions failed: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc migrateLegacyAIEditorActions(data *aiEditorActionsData, persist bool) (err error) {\n\tlocalStorage := GetLocalStorage()\n\tlegacyRaw, ok := localStorage[legacyAIEditorActionsStorageKey]\n\tif !ok {\n\t\treturn nil\n\t}\n","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/ai_editor.go#L175-L211","documentation":"saveAIEditorActions persists the actions file and first ensures its parent directory exists via os.MkdirAll(dirPath, 0755). This error wraps the MkdirAll failure. Thrown by SaveAIEditorAction, RemoveAIEditorAction, and migrateLegacyAIEditorActions.","triggerScenarios":"Calling SaveAIEditorAction/RemoveAIEditorAction when the storage directory under the workspace data path cannot be created — read-only filesystem, missing parent with no write permission, or a file occupying the directory path.","commonSituations":"Workspace on a read-only mount or CD-ROM; data directory owned by another user after restore; a regular file named like the expected storage directory exists; full disk preventing inode allocation.","solutions":["Check permissions on the workspace data directory and create the storage directory manually if needed (mkdir -p with correct ownership).","Verify the target directory path is not occupied by a regular file; remove/rename that file.","Ensure the volume is writable and not full; remount read-only filesystems read-write.","Read the wrapped OS error (%w) in the kernel log for the exact errno (EACCES, EROFS, ENOTDIR)."],"exampleFix":"// before: running kernel with a read-only workspace mount\n./siyuan --workspace /mnt/readonly/workspace\n// after: writable workspace\nmount -o remount,rw /mnt/readonly && ./siyuan --workspace /mnt/readonly/workspace","handlingStrategy":"retry","validationCode":"// ensure the target directory can be created before calling the API\nconst fs = require('fs');\nconst dir = workspace + '/data/storage';\nif (fs.existsSync(dir) && !fs.statSync(dir).isDirectory()) throw new Error('path occupied by a file');","typeGuard":null,"tryCatchPattern":"try {\n  await fetchSyncPost('/api/ai/editor/saveAIEditorAction', { id, name, action });\n} catch (e) {\n  if (/create AI editor actions directory failed/.test(e.message)) {\n    // fix permissions/remount rw, then retry with backoff\n  }\n}","preventionTips":["Run the kernel against a writable volume","Ensure no regular file occupies the storage directory path","Fix ownership after backup/restore (chown to kernel user)","Monitor free disk space/inodes"],"tags":["filesystem","mkdir","permissions","persistence"],"backgroundTag":"mkdir-permission-denied","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"}