{"record":{"id":"a73acf18523acdfc","repo":"usebruno/bruno","slug":"failed-to-minify","errorCode":null,"errorMessage":"Failed to minify","messagePattern":"Failed to minify","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/bruno-js/src/bru.js","lineNumber":101,"sourceCode":"    this._runtimeVarsDirty = false;\n    // Holds credential IDs to be reset after script execution\n    this.oauth2CredentialsToReset = [];\n    this.runner = {\n      skipRequest: () => {\n        this.skipRequest = true;\n      },\n      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          }","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-js/src/bru.js#L83-L119","documentation":"`bru.utils.minifyJson` (and identically `minifyXml`) throw the bare `Failed to minify` only when the input is `null` or `undefined`; later branches add `: ${err.message}` for parse failures. It is a null-input guard on the test-script helper.","triggerScenarios":"Calling `bru.utils.minifyJson(null)` or `bru.utils.minifyJson(undefined)` (or `minifyXml(null/undefined)`) inside a Bruno test/pre-request script.","commonSituations":"Script reads `req.body` or a parsed JSON var that is null (no body set, JSON.parse returned null, or a missing response field) and pipes it straight into `minifyJson`; an unset variable; a conditional response shape.","solutions":["Guard the call: `if (x != null) bru.utils.minifyJson(x)`.","Default to a safe value: `bru.utils.minifyJson(x ?? {})` for JSON or `x ?? ''` for XML.","Log the variable before calling to find which upstream field is null.","Use `typeof x !== 'undefined'` checks for variables that may be undeclared."],"exampleFix":"// before\nconst min = bru.utils.minifyJson(req.body);   // req.body is null\n\n// after\nconst min = req.body == null ? '' : bru.utils.minifyJson(req.body);","handlingStrategy":"validation","validationCode":"function safeMinifyJson(x) {\n  if (x === null || x === undefined) return '';\n  return bru.utils.minifyJson(x);\n}\nconst min = safeMinifyJson(maybeNullBody);","typeGuard":"function isMinifiable(v: unknown): v is string | object {\n  return v !== null && v !== undefined && (typeof v === 'string' || typeof v === 'object');\n}","tryCatchPattern":"try { bru.utils.minifyJson(x); }\ncatch (e) { if (/^Failed to minify$/.test(e.message)) { /* input was null/undefined; skip */ } else throw e; }","preventionTips":["Null-check before calling minifyJson/minifyXml.","Default absent bodies to '{}' or '' depending on helper.","Log the variable name when the helper throws to locate the missing field."],"tags":["scripts","bru","json","validation","runtime"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}