{"record":{"id":"a1f3ad259a4a30ef","repo":"siyuan-note/siyuan","slug":"response-msg-blockfold","errorCode":null,"errorMessage":"response.msg","messagePattern":"response\\.msg","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/src/protyle/util/blockFold.ts","lineNumber":330,"sourceCode":"    };\n    const addScope = (scope: ParentNode, occurrenceID?: string) => {\n        if (scope instanceof Element) {\n            addCandidate(scope, occurrenceID);\n        }\n        scope.querySelectorAll(\"[data-type='NodeHeading'], .li, .bq, .sb, .callout\").forEach(element => {\n            addCandidate(element, occurrenceID);\n        });\n    };\n\n    const scopes = await Promise.all(nodeElements.map(async (element) => {\n        let fullHTML = \"\";\n        if (element.getAttribute(\"data-type\") === \"NodeHeading\") {\n            const response = await fetchSyncPost(\"/api/block/getHeadingChildrenDOM\", {\n                id: element.getAttribute(\"data-node-id\"),\n                removeFoldAttr: false,\n            });\n            if (response.code !== 0) {\n                throw new Error(response.msg);\n            }\n            fullHTML = response.data;\n        } else if (element.querySelector('[data-type=\"NodeHeading\"][fold=\"1\"]')) {\n            const response = await fetchSyncPost(\"/api/block/getBlockDOM\", {\n                id: element.getAttribute(\"data-node-id\"),\n                notebook: protyle.notebookId,\n            });\n            if (response.code !== 0) {\n                throw new Error(response.msg);\n            }\n            fullHTML = response.data.dom;\n        }\n        return {element, fullHTML, occurrenceID: getViewFoldOccurrenceID(protyle, element)};\n    }));\n    scopes.forEach(({element, fullHTML, occurrenceID}) => {\n        if (fullHTML) {\n            const template = document.createElement(\"template\");\n            template.innerHTML = fullHTML;","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/protyle/util/blockFold.ts#L312-L348","documentation":"foldBlocksRecursively0 fetches all child DOM of a heading via /api/block/getHeadingChildrenDOM. When the kernel responds with a non-zero code, the raw response.msg text is thrown as an Error so the recursive fold operation aborts with the backend's message.","triggerScenarios":"Calling foldBlocksRecursively on a NodeHeading whose /api/block/getHeadingChildrenDOM request fails — e.g. the block ID no longer exists (stale DOM), the notebook is closed/syncing, or the kernel returned an internal error for that block.","commonSituations":"Document changed in another window/sync while folding, leaving a stale data-node-id; kernel busy or restarting; database index out of sync with .sy files so the block lookup fails.","solutions":["Catch the error in the fold action handler and show response.msg to the user, then refresh/ Reload the document to get fresh node IDs","Re-index the notebook (Rebuild Index) if block IDs are stale due to index/database mismatch","Retry the fold after the document tree has been refreshed so element carries a valid data-node-id","Check kernel logs for the underlying error returned by getHeadingChildrenDOM"],"exampleFix":"// before\nfoldBlocksRecursively(protyle, element); // unhandled throw on API failure\n// after\ntry {\n  await foldBlocksRecursively(protyle, element);\n} catch (e) {\n  showMessage(e.message);\n  reloadProtyle(protyle, false); // refresh stale DOM\n}","handlingStrategy":"try-catch","validationCode":"if (!element.getAttribute(\"data-node-id\")) {\n  throw new Error(\"Cannot fold: element has no data-node-id\");\n}","typeGuard":"const isApiResponse = (r: unknown): r is {code: number, msg: string, data: unknown} =>\n  typeof r === \"object\" && r !== null && \"code\" in r && \"msg\" in r;","tryCatchPattern":"try {\n  await foldBlocksRecursively(protyle, element);\n} catch (e) {\n  showMessage(e.message || \"Fold failed\");\n  reloadProtyle(protyle, false);\n}","preventionTips":["Refresh protyle content after sync/remote edits before folding","Rebuild notebook index when block lookups fail persistently","Check that the block still exists before recursive fold","Watch kernel logs for getHeadingChildrenDOM failures"],"tags":["api","fold","kernel"],"backgroundTag":"http-error-response","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"}