{"record":{"id":"c763aaf7ec78dc1a","repo":"usebruno/bruno","slug":"failed-to-minify-err-message-err","errorCode":null,"errorMessage":"Failed to minify: ${err?.message || err}","messagePattern":"Failed to minify: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-js/src/bru.js","lineNumber":108,"sourceCode":"      stopExecution: () => {\n        this.stopExecution = true;\n      },\n      setNextRequest: (nextRequest) => {\n        this.nextRequest = nextRequest;\n      }\n    };\n\n    this.utils = {\n      minifyJson: (json) => {\n        if (json === null || json === undefined) {\n          throw new Error('Failed to minify');\n        }\n\n        if (typeof json === 'object') {\n          try {\n            return JSON.stringify(json);\n          } catch (err) {\n            throw new Error(`Failed to minify: ${err?.message || err}`);\n          }\n        }\n\n        if (typeof json === 'string') {\n          const trimmed = json.trim();\n          if (trimmed === '') return trimmed;\n          try {\n            return JSON.stringify(JSON.parse(trimmed));\n          } catch (err) {\n            throw new Error(`Failed to minify: ${err?.message || err}`);\n          }\n        }\n\n        throw new TypeError('minifyJson expects a string or object');\n      },\n\n      minifyXml: (xml) => {\n        if (xml === null || xml === undefined) {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-js/src/bru.js#L90-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove circular references from the object before passing it to minifyJson (e.g., use a replacer function or strip self-referential keys).","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)).","Use a safe-serialization library like 'json-stringify-safe' or 'flatted' to pre-process the object."],"exampleFix":"// before\nconst obj = res.getBody(); // may contain circular refs\nconst min = bru.utils.minifyJson(obj);\n\n// after\nconst obj = res.getBody();\n// strip circular references with a replacer\nconst seen = new WeakSet();\nconst safe = JSON.parse(JSON.stringify(obj, (key, val) => {\n  if (typeof val === 'object' && val !== null) {\n    if (seen.has(val)) return undefined;\n    seen.add(val);\n  }\n  if (typeof val === 'bigint') return val.toString();\n  return val;\n}));\nconst min = bru.utils.minifyJson(safe);","handlingStrategy":"validation","validationCode":"function isJsonSerializable(obj) {\n  if (typeof obj !== 'object' || obj === null) return false;\n  const seen = new WeakSet();\n  try {\n    JSON.stringify(obj, (key, val) => {\n      if (typeof val === 'object' && val !== null) {\n        if (seen.has(val)) return undefined;\n        seen.add(val);\n      }\n      if (typeof val === 'bigint') return val.toString();\n      if (typeof val === 'function' || typeof val === 'symbol') return undefined;\n      return val;\n    });\n    return true;\n  } catch {\n    return false;\n  }\n}\n// before calling: if (isJsonSerializable(obj)) bru.utils.minifyJson(obj);","typeGuard":"function isMinifiableJsonInput(val) {\n  return val !== null && val !== undefined && (typeof val === 'object' || typeof val === 'string');\n}","tryCatchPattern":"try {\n  const minified = bru.utils.minifyJson(obj);\n} catch (e) {\n  if (e.message.startsWith('Failed to minify')) {\n    console.error('Object could not be serialized to JSON:', e.message);\n  }\n}","preventionTips":["Strip circular references from response/request objects before passing to minifyJson.","Convert BigInt values to strings before serialization.","Test minifyJson calls with a small representative sample of your data first."],"tags":["json","serialization","minify","circular-reference"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}