usebruno/bruno · error · Error

Failed to minify: ${err?.message || err}

Error message

Failed to minify: ${err?.message || err}

What it means

Thrown by bru.utils.minifyJson when JSON.stringify fails on an object input. This occurs when the object contains values JSON cannot serialize, such as circular references, BigInt values, or functions. The wrapped error message preserves the underlying stringify failure reason.

Source

Thrown at packages/bruno-js/src/bru.js:108

      stopExecution: () => {
        this.stopExecution = true;
      },
      setNextRequest: (nextRequest) => {
        this.nextRequest = nextRequest;
      }
    };

    this.utils = {
      minifyJson: (json) => {
        if (json === null || json === undefined) {
          throw new Error('Failed to minify');
        }

        if (typeof json === 'object') {
          try {
            return JSON.stringify(json);
          } catch (err) {
            throw new Error(`Failed to minify: ${err?.message || err}`);
          }
        }

        if (typeof json === 'string') {
          const trimmed = json.trim();
          if (trimmed === '') return trimmed;
          try {
            return JSON.stringify(JSON.parse(trimmed));
          } catch (err) {
            throw new Error(`Failed to minify: ${err?.message || err}`);
          }
        }

        throw new TypeError('minifyJson expects a string or object');
      },

      minifyXml: (xml) => {
        if (xml === null || xml === undefined) {

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Remove circular references from the object before passing it to minifyJson (e.g., use a replacer function or strip self-referential keys).
  2. Convert any BigInt values to strings or numbers before calling minifyJson: const safe = JSON.parse(JSON.stringify(obj, (k,v) => typeof v === 'bigint' ? v.toString() : v)).
  3. Use a safe-serialization library like 'json-stringify-safe' or 'flatted' to pre-process the object.

Example fix

// before
const obj = res.getBody(); // may contain circular refs
const min = bru.utils.minifyJson(obj);

// after
const obj = res.getBody();
// strip circular references with a replacer
const seen = new WeakSet();
const safe = JSON.parse(JSON.stringify(obj, (key, val) => {
  if (typeof val === 'object' && val !== null) {
    if (seen.has(val)) return undefined;
    seen.add(val);
  }
  if (typeof val === 'bigint') return val.toString();
  return val;
}));
const min = bru.utils.minifyJson(safe);
Defensive patterns

Strategy: validation

Validate before calling

function isJsonSerializable(obj) {
  if (typeof obj !== 'object' || obj === null) return false;
  const seen = new WeakSet();
  try {
    JSON.stringify(obj, (key, val) => {
      if (typeof val === 'object' && val !== null) {
        if (seen.has(val)) return undefined;
        seen.add(val);
      }
      if (typeof val === 'bigint') return val.toString();
      if (typeof val === 'function' || typeof val === 'symbol') return undefined;
      return val;
    });
    return true;
  } catch {
    return false;
  }
}
// before calling: if (isJsonSerializable(obj)) bru.utils.minifyJson(obj);

Type guard

function isMinifiableJsonInput(val) {
  return val !== null && val !== undefined && (typeof val === 'object' || typeof val === 'string');
}

Try / catch

try {
  const minified = bru.utils.minifyJson(obj);
} catch (e) {
  if (e.message.startsWith('Failed to minify')) {
    console.error('Object could not be serialized to JSON:', e.message);
  }
}

Prevention

When it happens

Trigger: Calling bru.utils.minifyJson(obj) where obj has a circular reference (e.g., obj.self = obj), contains a BigInt (e.g., {n: 123n}), or holds a Symbol-keyed property that stringify chokes on. The object branch at bru.js:104-110 calls JSON.stringify(json) and catches the failure.

Common situations: A script stores a request/response object that has circular references (common with axios or fetch response objects) and passes it to minifyJson. Another common case is using BigInt for large numeric IDs and forgetting JSON cannot serialize them.

Related errors


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