siyuan-note/siyuan · error

response?.msg || `Failed to ${action} view state`

Error message

response?.msg || `Failed to ${action} view state`

What it means

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.

Source

Thrown at app/src/util/viewState.ts:44

const getPatchByteLength = (values: TViewStateData, removeKeys: string[]) => {
    const json = JSON.stringify({values, removeKeys});
    if (typeof json !== "string") {
        throw new Error("Invalid view state patch");
    }
    const goCompatibleJSON = json.replace(/[<>&\u2028\u2029]/g, character => {
        return `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`;
    });
    return new TextEncoder().encode(goCompatibleJSON).byteLength;
};

const isViewStateData = (value: unknown): value is TViewStateData => {
    return typeof value === "object" && value !== null && !Array.isArray(value);
};

const checkResponse = (response: IWebSocketData, action: string) => {
    if (!response || response.code !== 0) {
        throw new Error(response?.msg || `Failed to ${action} view state`);
    }
};

const defaultTransport: IViewStateTransport = {
    async get(key) {
        const {fetchSyncPost} = await import("./fetch");
        const response = await fetchSyncPost("/api/storage/getViewState", {key});
        checkResponse(response, "get");
        return isViewStateData(response.data) ? response.data : {};
    },
    async patch(key, values, removeKeys) {
        const {fetchSyncPost} = await import("./fetch");
        const response = await fetchSyncPost("/api/storage/patchViewState", {key, values, removeKeys});
        checkResponse(response, "patch");
    },
};

const validateIdentityPart = (name: string, value: string) => {

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Check kernel logs for the storage API failure
  2. Verify the view-state key exists and is within size limits
  3. Retry after confirming the kernel and workspace are healthy
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at app/src/util/viewState.ts:44 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/7e55f74e523feac3. Report an issue: GitHub.