{"record":{"id":"2cc9145d2182575a","repo":"usebruno/bruno","slug":"invalid-variable-at-index-index-expected-an-ob","errorCode":null,"errorMessage":"Invalid variable at index ${index}: expected an object","messagePattern":"Invalid variable at index (.+?): expected an object","errorType":"validation","errorClass":"BrunoError","httpStatus":null,"severity":"error","filePath":"packages/bruno-app/src/utils/importers/bruno-environment.js","lineNumber":16,"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\n  };\n};\n\nconst processEnvironmentData = (data, fileName) => {\n  try {\n    // Handle new single-file format with environments array","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-app/src/utils/importers/bruno-environment.js#L1-L34","documentation":"Thrown inside the env.variables.forEach loop when a single variable entry is not an object. The index in the message pinpoints the offending slot in the variables array.","triggerScenarios":"variables array contains a null, a string, a number, or any primitive at the reported index, e.g. [null, {\"name\":\"X\"}] fails at index 0; [\"BASE_URL\"] fails at index 0.","commonSituations":"Trailing commas producing null holes, copying a variable name as a bare string instead of an object, or partial exports that emit null for deleted variables.","solutions":["Inspect the variables array at the reported index and replace the primitive/null with a full variable object.","Remove empty slots if the variable is not needed.","Re-export the environment from Bruno rather than hand-editing."],"exampleFix":"// before\n\"variables\": [ \"BASE_URL\", { \"name\": \"KEY\", \"value\": \"v\" } ]\n// after\n\"variables\": [\n  { \"name\": \"BASE_URL\", \"value\": \"https://api\", \"enabled\": true },\n  { \"name\": \"KEY\", \"value\": \"v\", \"enabled\": true }\n]","handlingStrategy":"validation","validationCode":"env.variables.forEach((v, i) => {\n  if (!(v !== null && typeof v === 'object' && !Array.isArray(v))) {\n    throw new Error(`Variable at index ${i} is not an object`);\n  }\n});","typeGuard":"function isVariableEntry(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  validateBrunoEnvironment(env);\n} catch (err) {\n  const m = err.message.match(/Invalid variable at index (\\d+): expected an object/);\n  if (m) env.variables = env.variables.filter(isVariableEntry);\n  throw err;\n}","preventionTips":["Filter out null/primitive slots before import.","Re-export environments instead of hand-editing array contents.","Validate each variable entry shape before import."],"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"}