{"record":{"id":"70efe2d878e8fc41","repo":"siyuan-note/siyuan","slug":"panic-during-siyuan-client-fetch-v","errorCode":null,"errorMessage":"panic during siyuan.client.fetch: %v","messagePattern":"panic during siyuan\\.client\\.fetch: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_client.go","lineNumber":106,"sourceCode":"\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\trunErr := p.worker.Run(func(rt *goja.Runtime) (_ any, err error) {\n\t\t\tif argErr != nil {\n\t\t\t\terr = argErr\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgo func() {\n\t\t\t\tvar err error\n\t\t\t\tdefer func() {\n\t\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\t\terr = fmt.Errorf(\"panic during siyuan.client.fetch: %v\", r)\n\t\t\t\t\t}\n\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tp.worker.Run(func(rt *goja.Runtime) (_ any, _ error) {\n\t\t\t\t\t\t\tif rejectErr := reject(rt.NewGoError(err)); rejectErr != nil {\n\t\t\t\t\t\t\t\tlogging.LogErrorf(\"[plugin:%s] siyuan.client.fetch reject: %v\", p.Name, rejectErr)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}, nil)\n\t\t\t\t\t}\n\t\t\t\t}()\n\n\t\t\t\ttargetURL := fmt.Sprintf(\"http://127.0.0.1:%s%s\", util.ServerPort, path)\n\t\t\t\tr := httpClient.R()\n\t\t\t\tfor k, v := range headers {\n\t\t\t\t\tr.SetHeader(k, v)\n\t\t\t\t}\n\t\t\t\tr.SetHeader(model.XAuthTokenKey, p.token)","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_client.go#L88-L124","documentation":"The actual HTTP request of siyuan.client.fetch runs on a background goroutine; any panic there (or a returned error) is converted into a rejection of the fetch promise with this message. It wraps unexpected kernel-side failures during request execution or response handling so plugin code sees a catchable error instead of crashing the runtime.","triggerScenarios":"A kernel-side panic while performing the HTTP request (e.g. transport failure handling, response body processing bug) or an error returned by the request path; the promise rejects with this wrapped message.","commonSituations":"Kernel unreachable or shutting down while a plugin request is in flight; very large or malformed responses triggering a processing bug; concurrent plugin requests during workspace close.","solutions":["Wrap the call in try/catch or .catch() and handle the rejection gracefully","Retry the request once after a short delay if the kernel was busy or restarting","Check the kernel log for the underlying panic/error detail","Verify the target API path exists and the payload size is reasonable"],"exampleFix":"// before\nconst res = await siyuan.client.fetch(\"/api/query/sql\", { method: \"POST\", body: JSON.stringify({ stmt }) });\n\n// after\nlet res;\ntry {\n  res = await siyuan.client.fetch(\"/api/query/sql\", { method: \"POST\", body: JSON.stringify({ stmt }) });\n} catch (e) {\n  console.error(\"siyuan.client.fetch failed:\", e);\n  res = null;\n}","handlingStrategy":"try-catch","validationCode":"async function safeKernelFetch(path, opts, retries = 1) {\n  for (let i = 0; i <= retries; i++) {\n    try { return await siyuan.client.fetch(path, opts); }\n    catch (e) { if (i === retries) throw e; await new Promise(r => setTimeout(r, 500)); }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await siyuan.client.fetch(path, opts);\n} catch (e) {\n  // every siyuan.client.fetch failure surfaces here; log and degrade gracefully\n  console.error(\"kernel fetch failed:\", e);\n}","preventionTips":["Always await inside try/catch — every fetch failure rejects the promise","Add one retry with backoff for transient kernel load","Keep request payloads small; check kernel logs for the underlying cause"],"tags":["plugin","fetch","panic","network"],"backgroundTag":"http-request-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"}