usebruno/bruno · error · TypeError

getRandomValues: Constructor ${obj.type} is not available

Error message

getRandomValues: Constructor ${obj.type} is not available

What it means

Thrown by deserializeTypedArray when `type` is on the allowlist but the matching constructor is not a function on the host's globalThis (e.g. BigInt64Array/BigUint64Array are unavailable in the runtime). This is a defense-in-depth check after the allowlist passes.

Source

Thrown at packages/bruno-js/src/sandbox/quickjs/shims/lib/utils.js:39

    '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

  1. Use a constructor that is definitely present — Uint8Array is the safest choice for random bytes.
  2. Check availability before use: `if (typeof BigInt64Array === 'function') { ... }`.
  3. Upgrade the host runtime if BigInt typed arrays are required.

Example fix

// before
crypto.getRandomValues(new BigInt64Array(4)); // constructor missing on host

// after
const arr = new Uint8Array(32);
crypto.getRandomValues(arr);
Defensive patterns

Strategy: type-guard

Validate before calling

function ctorAvailable(name) { return typeof globalThis[name] === 'function'; }
if (!ctorAvailable('BigInt64Array')) throw new TypeError('BigInt typed arrays unavailable');

Type guard

const isCtorAvailable = (name) => typeof globalThis[name] === 'function';

Try / catch

try { crypto.getRandomValues(new BigInt64Array(4)); }
catch (err) {
  if (/is not available/.test(err.message)) {
    crypto.getRandomValues(new Uint8Array(32));
  } else throw err;
}

Prevention

When it happens

Trigger: Passing a BigInt64Array or BigUint64Array to crypto.getRandomValues in a host runtime that does not expose BigInt typed-array constructors, or any case where globalThis[<allowed name>] is undefined/not-a-function.

Common situations: An older Node build with BigInt typed arrays disabled; a restricted runtime where the constructor was deleted or shadowed; sandbox host was started with flags that remove BigInt support.

Related errors


AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13). Data as JSON: /api/errors/c26d433b14b572c3. Report an issue: GitHub.