{"record":{"id":"786ca2aa4a6bcb3b","repo":"usebruno/bruno","slug":"invalid-environment-missing-or-invalid-variables","errorCode":null,"errorMessage":"Invalid environment: missing or invalid variables array","messagePattern":"Invalid environment: missing or invalid variables array","errorType":"validation","errorClass":"BrunoError","httpStatus":null,"severity":"error","filePath":"packages/bruno-app/src/utils/importers/bruno-environment.js","lineNumber":10,"sourceCode":"import { BrunoError } from 'utils/common/error';\nimport { buildEnvVariable, dedupeImportedSecrets } from 'utils/environments';\n\nconst validateBrunoEnvironment = (env) => {\n  if (!env || typeof env !== 'object') {\n    throw new BrunoError('Invalid environment: expected an object');\n  }\n\n  if (!Array.isArray(env.variables)) {\n    throw new BrunoError('Invalid environment: missing or invalid variables array');\n  }\n\n  // Validate each variable\n  env.variables.forEach((variable, index) => {\n    if (!variable || typeof variable !== 'object') {\n      throw new BrunoError(`Invalid variable at index ${index}: expected an object`);\n    }\n    if (!variable.name || typeof variable.name !== 'string') {\n      throw new BrunoError(`Invalid variable at index ${index}: missing or invalid name`);\n    }\n  });\n\n  const variables = env.variables.map((envVariable) => buildEnvVariable({ envVariable, withUuid: true }));\n\n  return {\n    name: env.name || 'Imported Environment',\n    variables: dedupeImportedSecrets(variables),\n    color: env.color","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-app/src/utils/importers/bruno-environment.js#L1-L28","documentation":"Thrown by validateBrunoEnvironment() after the top-level object check passes but env.variables is not an array. Bruno requires every environment to expose its variables as a JSON array, even an empty one.","triggerScenarios":"An environment object whose variables field is missing, null, a string, a number, an object/Map shape, or any non-array value. For example { \"name\": \"Prod\", \"variables\": { \"BASE_URL\": \"...\" } } (object instead of array).","commonSituations":"Hand-authoring an environment with a key-value map instead of an array of {name,value,enabled} objects, importing a partial export, or migrating from a Postman environment whose 'values' array was renamed incorrectly.","solutions":["Rewrite variables as an array: [{\"name\":\"BASE_URL\",\"value\":\"https://api\",\"enabled\":true}].","If the environment has no variables, use \"variables\": [].","Confirm each element follows Bruno's variable shape before re-importing."],"exampleFix":"// before\n{\n  \"name\": \"Prod\",\n  \"variables\": { \"BASE_URL\": \"https://api\" }\n}\n// after\n{\n  \"name\": \"Prod\",\n  \"variables\": [\n    { \"name\": \"BASE_URL\", \"value\": \"https://api\", \"enabled\": true }\n  ]\n}","handlingStrategy":"validation","validationCode":"if (!Array.isArray(env?.variables)) {\n  throw new Error('Environment variables must be an array');\n}","typeGuard":"function hasVariablesArray(env) {\n  return isBrunoEnvironment(env) && Array.isArray(env.variables);\n}","tryCatchPattern":"try {\n  validateBrunoEnvironment(env);\n} catch (err) {\n  if (err.message.includes('missing or invalid variables array')) {\n    env.variables = env.variables ? [] : [];\n  }\n  throw err;\n}","preventionTips":["Always emit variables as an array, even when empty.","Map Postman 'values' to Bruno 'variables' shape explicitly when converting.","Add a schema check in import UI before processing."],"tags":["import","validation","environment","json"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}