usebruno/bruno · error · TypeError
getRandomValues: Invalid typed array properties
Error message
getRandomValues: Invalid typed array properties
What it means
Thrown by deserializeTypedArray when the serialized object has a valid `type` but is missing the `array` field or has a non-number `length`. Both must be present and correctly typed to reconstruct the typed array.
Source
Thrown at packages/bruno-js/src/sandbox/quickjs/shims/lib/utils.js:34
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array',
'BigInt64Array',
'BigUint64Array'
]);
if (!obj || typeof obj !== 'object') {
throw new TypeError('getRandomValues: Invalid typed array object');
}
if (typeof obj.type !== 'string' || !allowedConstructors.has(obj.type)) {
throw new TypeError(`getRandomValues: Invalid or unsupported typed array type: ${obj.type}`);
}
if (!obj.array || typeof obj.length !== 'number') {
throw new TypeError('getRandomValues: Invalid typed array properties');
}
const ctor = globalThis[obj.type];
if (typeof ctor !== 'function') {
throw new TypeError(`getRandomValues: Constructor ${obj.type} is not available`);
}
return new ctor(obj.array, 0, obj.length);
}
module.exports = {
serializeTypedArray,
deserializeTypedArray
};
View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Do not construct the serialized shape by hand — produce it via serializeTypedArray.
- If you must, ensure both fields are present: { type: 'Uint8Array', array: [...], length: <number> }.
- Validate before passing: `typeof obj.length === 'number' && Array.isArray(obj.array)`.
Example fix
// before — length is a string after JSON round-trip
const bad = JSON.parse('{"type":"Uint8Array","array":[1,2],"length":"2"}');
crypto.getRandomValues(bad);
// after
const bad = JSON.parse('{"type":"Uint8Array","array":[1,2],"length":2}');
// or rebuild via serializeTypedArray(new Uint8Array(2)) Defensive patterns
Strategy: validation
Validate before calling
function assertSerialized(obj) {
if (!Array.isArray(obj.array) || typeof obj.length !== 'number') {
throw new TypeError('serialized typed array malformed');
}
} Type guard
const isSerializedTypedArray = (v) => v && typeof v === 'object' && Array.isArray(v.array) && typeof v.length === 'number';
Try / catch
try { crypto.getRandomValues(arr); }
catch (err) {
if (/Invalid typed array properties/.test(err.message)) {
crypto.getRandomValues(new Uint8Array(16));
} else throw err;
} Prevention
- Let serializeTypedArray build the shape; never hand-roll it.
- Be wary of JSON round-trips converting numeric fields to strings.
When it happens
Trigger: A serialized payload that was partially constructed or mutated — e.g. { type: 'Uint8Array' } with no array, or { type: 'Uint8Array', array: [...], length: '16' } (length as string).
Common situations: Manually editing or trimming the serialized object; a bug in serializeTypedArray callers; JSON round-trip that converted length to a string.
Related errors
- getRandomValues: Invalid typed array object
- getRandomValues: Invalid or unsupported typed array type: ${
- The "size" argument must be of type number
- The "size" argument must be >= 0
- The "size" argument is too large
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/160dacad0a88b5d2.
Report an issue: GitHub.