{"record":{"id":"71618d4f4ea2a5d1","repo":"siyuan-note/siyuan","slug":"marshal-legacy-ai-editor-actions-failed-w","errorCode":null,"errorMessage":"marshal legacy AI editor actions failed: %w","messagePattern":"marshal legacy AI editor actions failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/ai_editor.go","lineNumber":220,"sourceCode":"\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\n\tvar legacyActions []*legacyAIEditorAction\n\tif legacyJSON, isString := legacyRaw.(string); isString {\n\t\tif err = gulu.JSON.UnmarshalJSON([]byte(legacyJSON), &legacyActions); err != nil {\n\t\t\treturn fmt.Errorf(\"unmarshal legacy AI editor actions failed: %w\", err)\n\t\t}\n\t} else {\n\t\tlegacyJSON, marshalErr := gulu.JSON.MarshalJSON(legacyRaw)\n\t\tif marshalErr != nil {\n\t\t\treturn fmt.Errorf(\"marshal legacy AI editor actions failed: %w\", marshalErr)\n\t\t}\n\t\tif err = gulu.JSON.UnmarshalJSON(legacyJSON, &legacyActions); err != nil {\n\t\t\treturn fmt.Errorf(\"unmarshal legacy AI editor actions failed: %w\", err)\n\t\t}\n\t}\n\n\ttype actionKey struct {\n\t\tname   string\n\t\taction string\n\t}\n\texisting := make(map[actionKey]struct{}, len(data.Actions))\n\tfor _, action := range data.Actions {\n\t\texisting[actionKey{name: action.Name, action: action.Action}] = struct{}{}\n\t}\n\n\tchanged := false\n\tfor _, legacyAction := range legacyActions {\n\t\tif legacyAction == nil || (legacyAction.Name == \"\" && legacyAction.Memo == \"\") {","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/ai_editor.go#L202-L238","documentation":"migrateLegacyAIEditorActions handles the case where the legacy localStorage value is not a string: it re-marshals the raw value with gulu.JSON.MarshalJSON before unmarshalling into []*legacyAIEditorAction. This error wraps the re-marshal failure, indicating the raw stored value cannot be serialized (unsupported type or internal inconsistency). Thrown via GetAIEditorActions, SaveAIEditorAction, and RemoveAIEditorAction.","triggerScenarios":"Migration path where legacyRaw is a non-string (e.g. already-decoded array/object) and gulu.JSON.MarshalJSON fails — practically only when the in-memory decoded value contains non-JSON-safe data or the storage layer returned an unexpected type.","commonSituations":"Corrupted or hand-modified storage JSON producing an exotic decoded value; a kernel/storage-layer bug returning an unsupported runtime type; data injected by third-party tooling into the storage file.","solutions":["Check the wrapped error (%w) in the kernel log to identify the unsupported value/type.","Repair or reset the legacy storage entry in the workspace storage JSON so migration sees either a valid string or a normal JSON value.","If legacy data is unimportant, clear the legacy entry and recreate AI editor actions in the new format via the UI.","Treat repeated occurrences as an internal bug: capture the value type and report with kernel version."],"exampleFix":"// before: corrupt non-string legacy value in storage\n\"legacyKey\": {\"oops\": function}\n// after: normal decodable value\n\"legacyKey\": [{\"id\":\"20240101120000-a1b2c3d4e5f6\",\"name\":\"Summarize\",\"action\":\"summarize\"}]","handlingStrategy":"fallback","validationCode":"// ensure the legacy value round-trips through JSON before migration\ntry { JSON.parse(JSON.stringify(legacyRaw)); } catch (e) { /* reset the legacy entry */ }","typeGuard":null,"tryCatchPattern":"try {\n  const actions = await fetchSyncPost('/api/ai/editor/saveAIEditorAction', { id, name, action });\n} catch (e) {\n  if (/marshal legacy AI editor actions failed/.test(e.message)) {\n    // reset the legacy storage entry to a plain decodable value or clear it\n  }\n}","preventionTips":["Keep legacy storage values as plain JSON arrays/strings","Never inject non-JSON values into workspace storage files","Clear unneeded legacy entries before upgrading","Round-trip test storage data through JSON in maintenance scripts"],"tags":["json","migration","legacy","serialization"],"backgroundTag":"json-marshal-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"}