siyuan-note/siyuan · error
unsupported data type: %T
Error message
unsupported data type: %T
What it means
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.
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
Example fix
// before
await api.request({ data: { foo: 1 } });
// after
await api.request({ data: JSON.stringify({ foo: 1 }) }); Defensive patterns
Strategy: validation
Validate before calling
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); } Type guard
function isBinaryLike(v) { return typeof v === 'string' || v instanceof Uint8Array || v instanceof ArrayBuffer; } Try / catch
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; } } Prevention
- Stringify objects before sending as request data
- Use Buffer/Uint8Array/ArrayBuffer for binary payloads
- Type-check data parameters at the call site
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- js value cannot be exported to a valid Go value
- siyuan.server[ ][ ].handler is not a function
- failed to serialize config.
- failed to serialize inputSchema
- globalThis.siyuan.plugin.lifecycle is not an object
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/13aa52ee65cc020b.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/plugin/sandbox.go:485
// isJsValueNotNull checks if a goja.Value is not nil, undefined or null.
func isJsValueNotNull(jsValue goja.Value) bool {
return isJsValueNotUndefined(jsValue) && !goja.IsNull(jsValue)
}
// jsValueToBytes attempts to convert a goja.Value to a byte slice, supporting string, Buffer, ArrayBuffer, etc.
func jsValueToBytes(rt *goja.Runtime, value goja.Value) (data []byte, err error) {
if goValue := value.Export(); goValue != nil {
switch d := goValue.(type) {
case string: // string
data = []byte(d)
case []byte: // Buffer
data = d
case goja.ArrayBuffer: // ArrayBuffer
data = d.Bytes()
case buffer.Buffer: // ?
data = buffer.Bytes(rt, value)
default:
err = fmt.Errorf("unsupported data type: %T", goValue)
}
return
}
err = fmt.Errorf("js value cannot be exported to a valid Go value")
return
}
// getRequestHandler retrieves the handler function and its containing object for a given scope and request type from the plugin's JS context.
func getRequestHandler(rt *goja.Runtime, scope AccessScope, requestType RequestType) (handler goja.Callable, handlerObj *goja.Object, err error) {
// Get handler object: siyuan.server[scope][requestType]
handlerObjValue, getObjErr := getJsContextValue(rt, []any{"siyuan", "server", string(scope), string(requestType)})
if getObjErr != nil {
err = getObjErr
return
}
handlerObj = handlerObjValue.ToObject(rt)
if handlerObj == nil {View on GitHub (pinned to 9f775e8a12)