{"record":{"id":"c15e9ce5b922907d","repo":"siyuan-note/siyuan","slug":"handler-did-not-return-an-object","errorCode":null,"errorMessage":"handler did not return an object","messagePattern":"handler did not return an object","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"kernel/plugin/plugin.go","lineNumber":928,"sourceCode":"\t\t\terr = getHandlerErr\n\t\t\treturn\n\t\t}\n\n\t\tjsRequest, convertErr := requestGoToJs(p, rt, request)\n\t\tif convertErr != nil {\n\t\t\terr = convertErr\n\t\t\treturn\n\t\t}\n\n\t\tinvokeFunction(func(rt *goja.Runtime, result *CallResult) {\n\t\t\tif result.Error != nil {\n\t\t\t\tdone <- &handleResult{Error: result.Error}\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tresponseObj := result.Value.ToObject(rt)\n\t\t\tif responseObj == nil {\n\t\t\t\tdone <- &handleResult{Error: fmt.Errorf(\"handler did not return an object\")}\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// convert response.body?.raw?.data from (string | Buffer | ArrayBuffer) to []byte\n\t\t\tvar raw *[]byte\n\t\t\tif bodyValue := responseObj.Get(\"body\"); isJsValueNotNull(bodyValue) {\n\t\t\t\t// response.body\n\t\t\t\tif bodyObj := bodyValue.ToObject(rt); bodyObj != nil {\n\t\t\t\t\tif rawValue := bodyObj.Get(\"raw\"); isJsValueNotNull(rawValue) {\n\t\t\t\t\t\t// response.body.raw\n\t\t\t\t\t\tif rawObj := rawValue.ToObject(rt); rawObj != nil {\n\t\t\t\t\t\t\tif dataValue := rawObj.Get(\"data\"); isJsValueNotNull(dataValue) {\n\t\t\t\t\t\t\t\t// response.body.raw.data\n\t\t\t\t\t\t\t\tdataBytes, convertErr := jsValueToBytes(rt, dataValue)\n\t\t\t\t\t\t\t\tif convertErr == nil {\n\t\t\t\t\t\t\t\t\traw = &dataBytes\n\t\t\t\t\t\t\t\t\trawObj.Set(\"data\", goja.Null())\n\t\t\t\t\t\t\t\t}","sourceCodeStart":910,"sourceCodeEnd":946,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/plugin/plugin.go#L910-L946","documentation":"Returned when an HTTP request handler's resolved Promise value cannot be turned into a JS object via ToObject (result is null/undefined/number/string). The kernel requires the handler to return a plain object shaped like { status, headers, body } so it can extract the response.","triggerScenarios":"An onRequest HTTP handler returns undefined, null, a primitive, or forgets to return the response object, so result.Value.ToObject(rt) yields nil.","commonSituations":"Handler function missing a return statement, returning a fetch Response directly instead of a plain {status, headers, body} object, or an early return path that yields nothing.","solutions":["Make the handler always return a response object: return { status: 200, headers: {}, body: { raw: { mime: 'text/plain', data: 'ok' } } }.","Add an explicit default response at the end of the handler so no code path falls through.","Type the handler return in TS as Response so the compiler flags missing returns."],"exampleFix":"// before\nserver.onRequest('GET', '/x', async (req) => {\n  if (req.query.bad) return; // undefined -> error\n  return { status: 200, body: { raw: { mime: 'text/plain', data: 'ok' } } };\n});\n\n// after\nserver.onRequest('GET', '/x', async (req) => {\n  if (req.query.bad) return { status: 400, body: { raw: { mime: 'text/plain', data: 'bad' } } };\n  return { status: 200, body: { raw: { mime: 'text/plain', data: 'ok' } } };\n});","handlingStrategy":"type-guard","validationCode":"function isResponseObject(v: unknown): v is { status: number; headers?: Record<string,string>; body?: unknown } { return !!v && typeof v === 'object' && typeof (v as any).status === 'number'; }","typeGuard":"function isResponseObject(v: unknown): v is { status: number; headers?: Record<string,string>; body?: unknown } { return !!v && typeof v === 'object' && typeof (v as any).status === 'number'; }","tryCatchPattern":null,"preventionTips":["Always return a response object from every code path in the handler.","Type the handler return so TS flags missing returns.","Add a default response as the last statement."],"tags":["plugin","server","http","handler","contract"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}