{"record":{"id":"2a395896e9054a64","repo":"usebruno/bruno","slug":"invalid-variable-at-index-index-missing-or-inv","errorCode":null,"errorMessage":"Invalid variable at index ${index}: missing or invalid name","messagePattern":"Invalid variable at index (.+?): missing or invalid name","errorType":"validation","errorClass":"BrunoError","httpStatus":null,"severity":"error","filePath":"packages/bruno-app/src/utils/importers/bruno-environment.js","lineNumber":19,"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\n    if (data.info && data.info.type === 'bruno-environment' && Array.isArray(data.environments)) {\n      return data.environments.map((env, index) => {\n        try {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-app/src/utils/importers/bruno-environment.js#L1-L37","documentation":"Thrown by validateBrunoEnvironment() when a variable object passes the object check but its name field is missing, empty, or not a string. Bruno requires every variable to carry a string name.","triggerScenarios":"A variable object such as {\"value\":\"v\"} (no name), {\"name\":42} (numeric name), or {\"name\":\"\"} (empty string triggers the truthy !variable.name check).","commonSituations":"Stripping names during a transform, exporting from a tool that uses 'key' instead of 'name', or trailing whitespace/empty identifiers after a find-replace.","solutions":["Add a non-empty string name to the variable at the reported index.","Rename alternate key fields (key, id) to name.","Delete variables with no meaningful name rather than leaving them blank."],"exampleFix":"// before\n{ \"value\": \"https://api\", \"enabled\": true }\n// after\n{ \"name\": \"BASE_URL\", \"value\": \"https://api\", \"enabled\": true }","handlingStrategy":"validation","validationCode":"env.variables.forEach((v, i) => {\n  if (typeof v?.name !== 'string' || v.name.trim() === '') {\n    throw new Error(`Variable at index ${i} needs a non-empty string name`);\n  }\n});","typeGuard":"function hasValidName(v) {\n  return typeof v?.name === 'string' && v.name.length > 0;\n}","tryCatchPattern":"try {\n  validateBrunoEnvironment(env);\n} catch (err) {\n  if (err.message.includes('missing or invalid name')) {\n    env.variables = env.variables.filter(hasValidName);\n  }\n  throw err;\n}","preventionTips":["Ensure every variable has a non-empty string 'name' field.","Rename 'key'/'id' fields to 'name' when transforming from other tools.","Drop unnamed variables instead of leaving them blank."],"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"}