{"record":{"id":"13aa52ee65cc020b","repo":"siyuan-note/siyuan","slug":"unsupported-data-type-t","errorCode":null,"errorMessage":"unsupported data type: %T","messagePattern":"unsupported data type: %T","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/sandbox.go","lineNumber":485,"sourceCode":"// isJsValueNotNull checks if a goja.Value is not nil, undefined or null.\nfunc isJsValueNotNull(jsValue goja.Value) bool {\n\treturn isJsValueNotUndefined(jsValue) && !goja.IsNull(jsValue)\n}\n\n// jsValueToBytes attempts to convert a goja.Value to a byte slice, supporting string, Buffer, ArrayBuffer, etc.\nfunc jsValueToBytes(rt *goja.Runtime, value goja.Value) (data []byte, err error) {\n\tif goValue := value.Export(); goValue != nil {\n\t\tswitch d := goValue.(type) {\n\t\tcase string: // string\n\t\t\tdata = []byte(d)\n\t\tcase []byte: // Buffer\n\t\t\tdata = d\n\t\tcase goja.ArrayBuffer: // ArrayBuffer\n\t\t\tdata = d.Bytes()\n\t\tcase buffer.Buffer: // ?\n\t\t\tdata = buffer.Bytes(rt, value)\n\t\tdefault:\n\t\t\terr = fmt.Errorf(\"unsupported data type: %T\", goValue)\n\t\t}\n\t\treturn\n\t}\n\terr = fmt.Errorf(\"js value cannot be exported to a valid Go value\")\n\treturn\n}\n\n// getRequestHandler retrieves the handler function and its containing object for a given scope and request type from the plugin's JS context.\nfunc getRequestHandler(rt *goja.Runtime, scope AccessScope, requestType RequestType) (handler goja.Callable, handlerObj *goja.Object, err error) {\n\t// Get handler object: siyuan.server[scope][requestType]\n\thandlerObjValue, getObjErr := getJsContextValue(rt, []any{\"siyuan\", \"server\", string(scope), string(requestType)})\n\tif getObjErr != nil {\n\t\terr = getObjErr\n\t\treturn\n\t}\n\n\thandlerObj = handlerObjValue.ToObject(rt)\n\tif handlerObj == nil {","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/sandbox.go#L467-L503","documentation":"jsValueToBytes converts a JS value passed from the plugin sandbox into a Go byte slice. It only accepts string, []byte (Buffer), goja.ArrayBuffer, and buffer.Buffer; any other exported Go type hits the default case and produces this error naming the offending Go type via %T.","triggerScenarios":"Calling an API from plugin code that passes a body/data argument which is not a string, Buffer, or ArrayBuffer - e.g. a plain JS object, number, boolean, array, or undefined-wrapped value.","commonSituations":"Passing a parsed JSON object as request body data, passing a number or null, or forgetting to stringify/serialize data before calling the kernel-facing API.","solutions":["Convert the value before calling: use JSON.stringify(obj), String(num), or a Buffer/Uint8Array","If it is a Uint8Array view over an ArrayBuffer, pass view.buffer or wrap it appropriately","Check the API's expected data type in the plugin API docs"],"exampleFix":"// before\nawait api.request({ data: { foo: 1 } });\n// after\nawait api.request({ data: JSON.stringify({ foo: 1 }) });","handlingStrategy":"validation","validationCode":"function assertBytesOk(v) { if (!(typeof v === 'string' || v instanceof Uint8Array || v instanceof ArrayBuffer)) throw new TypeError('data must be string, Buffer/Uint8Array, or ArrayBuffer, got ' + typeof v); }","typeGuard":"function isBinaryLike(v) { return typeof v === 'string' || v instanceof Uint8Array || v instanceof ArrayBuffer; }","tryCatchPattern":"try { await api.send(data); } catch (e) { if (String(e).includes('unsupported data type')) { data = JSON.stringify(data); await api.send(data); } else { throw e; } }","preventionTips":["Stringify objects before sending as request data","Use Buffer/Uint8Array/ArrayBuffer for binary payloads","Type-check data parameters at the call site"],"tags":["goja","plugin","type-error","serialization"],"backgroundTag":"unsupported-dtype","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"}