usebruno/bruno · error · TypeError
getRandomValues: Invalid typed array object
Error message
getRandomValues: Invalid typed array object
What it means
Thrown by deserializeTypedArray (QuickJS crypto shim utils) when the serialized value passed to crypto.getRandomValues is not a non-null object. The deserializer expects a shape like { type, array, length } produced by serializeTypedArray; anything else (null, undefined, number, string) fails this first guard.
Source
Thrown at packages/bruno-js/src/sandbox/quickjs/shims/lib/utils.js:26
function deserializeTypedArray(obj) {
// Allowed typed array constructors for crypto operations
const allowedConstructors = new Set([
'Int8Array',
'Uint8Array',
'Uint8ClampedArray',
'Int16Array',
'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);
}
View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Pass an actual typed array: `crypto.getRandomValues(new Uint8Array(16))`.
- Guard the call site: `if (!(arr instanceof Uint8Array)) throw new TypeError('arr must be a typed array')`.
- Initialize the variable before the call so it is never undefined.
Example fix
// before let iv; crypto.getRandomValues(iv); // iv is undefined // after const iv = new Uint8Array(12); crypto.getRandomValues(iv);
Defensive patterns
Strategy: type-guard
Validate before calling
function fillRandom(v) {
if (!(v && typeof v === 'object')) throw new TypeError('expected typed array');
return crypto.getRandomValues(v);
} Type guard
const isTypedArray = (v) => v != null && typeof v === 'object' && ArrayBuffer.isView(v) && !(v instanceof DataView);
Try / catch
try { crypto.getRandomValues(maybeArr); }
catch (err) {
if (/Invalid typed array object/.test(err.message)) {
crypto.getRandomValues(new Uint8Array(16));
} else throw err;
} Prevention
- Always construct a typed array before calling getRandomValues.
- Guard against undefined from failed upstream steps.
When it happens
Trigger: Calling crypto.getRandomValues(null), crypto.getRandomValues(undefined), crypto.getRandomValues(123), or crypto.getRandomValues('abc') inside a QuickJS-sandboxed script.
Common situations: A variable that was supposed to hold a typed array is undefined because an earlier step failed; a function default parameter leaked through; the wrong argument was passed (e.g. a plain number instead of a Uint8Array).
Related errors
- getRandomValues: Invalid or unsupported typed array type: ${
- getRandomValues: Invalid typed array properties
- 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/e7e4c0b2accadd3f.
Report an issue: GitHub.