{"record":{"id":"b122c38511f77b7f","repo":"siyuan-note/siyuan","slug":"failed-to-update-the-global-plugin-state","errorCode":null,"errorMessage":"Failed to update the global plugin state","messagePattern":"Failed to update the global plugin state","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/plugin/globalState.ts","lineNumber":53,"sourceCode":"\nexport const applyPluginReload = (app: App, data: IPluginReloadData = {}) => {\n    if (!isGlobalPluginState(data)) {\n        return reloadPlugin(app, data);\n    }\n    return getCoordinator(app).apply(data);\n};\n\nexport const syncGlobalPluginConfig = (app: App, petalDisabled: boolean) => {\n    getCoordinator(app).syncConfig(petalDisabled);\n};\n\nexport const subscribeGlobalPluginState = (app: App, listener: (state: IGlobalPluginStateSnapshot) => void) =>\n    getCoordinator(app).subscribe(listener);\n\nexport const setGlobalPluginsDisabled = async (app: App, petalDisabled: boolean) => {\n    const response = await fetchSyncPost(\"/api/setting/setBazaarPetalDisabled\", {petalDisabled});\n    if (response.code !== 0 || !response.data) {\n        throw new Error(response.msg || \"Failed to update the global plugin state\");\n    }\n    await applyPluginReload(app, response.data as TGlobalPluginReloadData);\n};\n","sourceCodeStart":35,"sourceCodeEnd":57,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/app/src/plugin/globalState.ts#L35-L57","documentation":"setGlobalPluginsDisabled posts petalDisabled to /api/setting/setBazaarPetalDisabled and requires code===0 plus data (the reload payload). Any missing data, non-zero code, or failed request throws with the kernel msg or this fallback, before applyPluginReload runs.","triggerScenarios":"Toggling the global 'disable all plugins' setting when the kernel call fails: response.code !== 0, response.data missing, or the request itself failed (undefined response).","commonSituations":"Kernel busy or restarted while switching the setting; a kernel bug returning no reload data; workspace locked by sync; API failure due to auth/token expiry in browser mode.","solutions":["Retry the toggle after confirming the kernel is responding","Check kernel logs for setBazaarPetalDisabled errors","Verify response.data is present — a missing payload indicates a kernel-side issue to report/fix","Ensure the workspace is not locked/unavailable during the change"],"exampleFix":"// before\nawait setGlobalPluginsDisabled(app, true);\n// after\ntry { await setGlobalPluginsDisabled(app, true); } catch (e) { showMessage(e.message); }","handlingStrategy":"try-catch","validationCode":"const resp = await fetchSyncPost(\"/api/setting/setBazaarPetalDisabled\", {petalDisabled}).catch(() => null); if (!resp || resp.code !== 0 || !resp.data) return false; return true;","typeGuard":"const hasReloadData = (r: any): r is {code: 0; data: TGlobalPluginReloadData} => r?.code === 0 && !!r?.data;","tryCatchPattern":"try { await setGlobalPluginsDisabled(app, disabled); } catch (e) { revertSwitch(); showMessage(e.message); }","preventionTips":["Verify kernel availability before toggling global settings","Revert the settings switch on failure","Check response.data presence to distinguish kernel bugs from request failures"],"tags":["api","plugins","settings"],"backgroundTag":"api-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"}