{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/plugin/sandbox.go#L467-L503","documentation":"jsValueToBytes converts a JS value to a Go byte slice, accepting string, []byte (Buffer), goja.ArrayBuffer, and buffer.Buffer. Any other exported Go type falls into the default branch and raises 'unsupported data type: %T' naming the actual type. It is the kernel's strictness when plugin APIs expect binary or text data.","triggerScenarios":"A plugin passes a non-binary JS value (plain object, number, boolean, array, function) to a kernel API whose data parameter is converted with jsValueToBytes — e.g. file/network APIs expecting string, Buffer, or ArrayBuffer.","commonSituations":"Passing a JSON object where a string/Buffer was expected; passing null/undefined-adjacent wrappers; passing a DataView (exports as plain object) instead of its .buffer ArrayBuffer; passing a number where a string was intended.","solutions":["Convert the value before calling the API: use JSON.stringify for objects, String(n) for numbers","For binary data pass an ArrayBuffer or Uint8Array's .buffer; for text pass a string","For DataView, pass dataView.buffer or new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength)"],"exampleFix":"// before\npluginApi.writeData({ raw: bytes }); // object\n// after\npluginApi.writeData(new Uint8Array(bytes).buffer);","handlingStrategy":"validation","validationCode":"function assertBytesLike(v) { if (typeof v !== 'string' && !(v instanceof ArrayBuffer) && !ArrayBuffer.isView(v)) { throw new TypeError('expected string, Buffer or ArrayBuffer, got ' + typeof v); } }","typeGuard":"const isBytesLike = (v) => typeof v === 'string' || v instanceof ArrayBuffer || ArrayBuffer.isView(v);","tryCatchPattern":"try { api.writeData(payload); } catch (e) { if (String(e).includes('unsupported data type')) { api.writeData(String(payload)); } }","preventionTips":["Normalize payloads at the plugin boundary: strings for text, ArrayBuffer/Uint8Array for binary","Convert objects with JSON.stringify and numbers with String() before passing to data APIs","For DataView, pass .buffer with explicit byteOffset/byteLength"],"tags":["goja","type-mismatch","binary-data"],"backgroundTag":"unsupported-dtype","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}