{"record":{"id":"c31caf55e3693402","repo":"siyuan-note/siyuan","slug":"read-ai-editor-actions-failed-w","errorCode":null,"errorMessage":"read AI editor actions failed: %w","messagePattern":"read AI editor actions failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/ai_editor.go","lineNumber":160,"sourceCode":"}\n\nfunc aiEditorActionsPath() string {\n\treturn filepath.Join(util.DataDir, \"storage\", \"ai\", \"editor\", \"actions.json\")\n}\n\nfunc loadAIEditorActions() (ret *aiEditorActionsData, err error) {\n\tret = &aiEditorActionsData{\n\t\tVersion: aiEditorActionsVersion,\n\t\tActions: []*AIEditorAction{},\n\t}\n\tdataPath := aiEditorActionsPath()\n\tif !filelock.IsExist(dataPath) {\n\t\treturn ret, nil\n\t}\n\n\tdata, err := filelock.ReadFile(dataPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read AI editor actions failed: %w\", err)\n\t}\n\tif err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshal AI editor actions failed: %w\", err)\n\t}\n\tif ret.Version != aiEditorActionsVersion {\n\t\treturn nil, fmt.Errorf(\"unsupported AI editor actions version [%d]\", ret.Version)\n\t}\n\tif ret.Actions == nil {\n\t\tret.Actions = []*AIEditorAction{}\n\t}\n\n\tids := make(map[string]struct{}, len(ret.Actions))\n\tfor _, action := range ret.Actions {\n\t\tif action == nil || !ast.IsNodeIDPattern(action.ID) || (action.Name == \"\" && action.Action == \"\") {\n\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)","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/ai_editor.go#L142-L178","documentation":"loadAIEditorActions reads the persisted AI editor actions JSON file (aiEditorActionsPath) via filelock.ReadFile. This error wraps the underlying OS error when the file exists but cannot be read (permissions, IO failure, concurrent lock). It is surfaced by GetAIEditorActions, SaveAIEditorAction, and RemoveAIEditorAction.","triggerScenarios":"Calling GetAIEditorActions/SaveAIEditorAction/RemoveAIEditorAction when data/storage/ai-editor-actions.json (or equivalent path) exists but ReadFile fails — e.g. permission change, disk error, file locked by another process, or the file was replaced by a directory.","commonSituations":"Workspace data directory permissions changed after backup/restore (rsync with wrong ownership); antivirus or sync tools (OneDrive/Dropbox) holding the file; disk full or I/O errors; the file path turned into a directory during a manual edit of the data folder.","solutions":["Check file permissions/ownership of the AI editor actions file in the workspace data directory and restore read access (chmod/chown).","Stop processes locking the file (sync/AV clients) and retry the API call.","Verify the path is a regular file, not a directory; restore it from backup or delete it so it is recreated.","Inspect the wrapped error (%w) in the kernel log for the exact OS-level cause (EACCES, EIO, EISDIR)."],"exampleFix":"// before: blindly calling API without checking file state\nactions, err := GetAIEditorActions()\n// after: check file readability first\nif path, e := aiEditorActionsPath(); e == nil {\n    if _, e := os.Stat(path); e != nil && !os.IsNotExist(e) { /* inspect e */ }\n}\nactions, err := GetAIEditorActions()","handlingStrategy":"try-catch","validationCode":"const stat = await fetch('/api/filetree/getDocInfo'); // or check file exists/readable before mutating actions\nif (stat && stat.err) console.warn('storage file state:', stat.err);","typeGuard":null,"tryCatchPattern":"try {\n  const actions = await fetchSyncPost('/api/ai/editor/getAIEditorActions', {});\n  if (actions.code !== 0) throw new Error(actions.msg);\n} catch (e) {\n  if (/read AI editor actions failed/.test(e.message)) {\n    // inspect file permissions/locks; fall back to defaults\n  }\n}","preventionTips":["Keep workspace data directory owned/writable by the kernel user","Exclude the workspace from aggressive sync/AV tools or pause them during use","Monitor disk health and free space","Never replace data files with directories during manual maintenance"],"tags":["filesystem","io","file-locking","persistence"],"backgroundTag":"file-read-failed","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"}