{"record":{"id":"7e55f74e523feac3","repo":"siyuan-note/siyuan","slug":"response-msg-failed-to-action-view-state","errorCode":null,"errorMessage":"response?.msg || `Failed to ${action} view state`","messagePattern":"response\\?\\.msg \\|\\| `Failed to (.+?) view state`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/util/viewState.ts","lineNumber":44,"sourceCode":"\nconst getPatchByteLength = (values: TViewStateData, removeKeys: string[]) => {\n    const json = JSON.stringify({values, removeKeys});\n    if (typeof json !== \"string\") {\n        throw new Error(\"Invalid view state patch\");\n    }\n    const goCompatibleJSON = json.replace(/[<>&\\u2028\\u2029]/g, character => {\n        return `\\\\u${character.charCodeAt(0).toString(16).padStart(4, \"0\")}`;\n    });\n    return new TextEncoder().encode(goCompatibleJSON).byteLength;\n};\n\nconst isViewStateData = (value: unknown): value is TViewStateData => {\n    return typeof value === \"object\" && value !== null && !Array.isArray(value);\n};\n\nconst checkResponse = (response: IWebSocketData, action: string) => {\n    if (!response || response.code !== 0) {\n        throw new Error(response?.msg || `Failed to ${action} view state`);\n    }\n};\n\nconst defaultTransport: IViewStateTransport = {\n    async get(key) {\n        const {fetchSyncPost} = await import(\"./fetch\");\n        const response = await fetchSyncPost(\"/api/storage/getViewState\", {key});\n        checkResponse(response, \"get\");\n        return isViewStateData(response.data) ? response.data : {};\n    },\n    async patch(key, values, removeKeys) {\n        const {fetchSyncPost} = await import(\"./fetch\");\n        const response = await fetchSyncPost(\"/api/storage/patchViewState\", {key, values, removeKeys});\n        checkResponse(response, \"patch\");\n    },\n};\n\nconst validateIdentityPart = (name: string, value: string) => {","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/app/src/util/viewState.ts#L26-L62","documentation":"checkResponse in the view-state service: the kernel /api/storage/get or patchViewState call answered with a non-zero code, so the transport failed. The thrown message is the kernel response msg, or the fallback 'Failed to get/patch view state' when no msg was provided.","triggerScenarios":"Thrown at app/src/util/viewState.ts:44 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check kernel logs for the storage API failure","Verify the view-state key exists and is within size limits","Retry after confirming the kernel and workspace are healthy"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}