usebruno/bruno · error · BrunoError

Invalid variable at index ${index}: missing or invalid name

Error message

Invalid variable at index ${index}: missing or invalid name

What it means

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.

Source

Thrown at packages/bruno-app/src/utils/importers/bruno-environment.js:19

import { BrunoError } from 'utils/common/error';
import { buildEnvVariable, dedupeImportedSecrets } from 'utils/environments';

const validateBrunoEnvironment = (env) => {
  if (!env || typeof env !== 'object') {
    throw new BrunoError('Invalid environment: expected an object');
  }

  if (!Array.isArray(env.variables)) {
    throw new BrunoError('Invalid environment: missing or invalid variables array');
  }

  // Validate each variable
  env.variables.forEach((variable, index) => {
    if (!variable || typeof variable !== 'object') {
      throw new BrunoError(`Invalid variable at index ${index}: expected an object`);
    }
    if (!variable.name || typeof variable.name !== 'string') {
      throw new BrunoError(`Invalid variable at index ${index}: missing or invalid name`);
    }
  });

  const variables = env.variables.map((envVariable) => buildEnvVariable({ envVariable, withUuid: true }));

  return {
    name: env.name || 'Imported Environment',
    variables: dedupeImportedSecrets(variables),
    color: env.color
  };
};

const processEnvironmentData = (data, fileName) => {
  try {
    // Handle new single-file format with environments array
    if (data.info && data.info.type === 'bruno-environment' && Array.isArray(data.environments)) {
      return data.environments.map((env, index) => {
        try {

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Add a non-empty string name to the variable at the reported index.
  2. Rename alternate key fields (key, id) to name.
  3. Delete variables with no meaningful name rather than leaving them blank.

Example fix

// before
{ "value": "https://api", "enabled": true }
// after
{ "name": "BASE_URL", "value": "https://api", "enabled": true }
Defensive patterns

Strategy: validation

Validate before calling

env.variables.forEach((v, i) => {
  if (typeof v?.name !== 'string' || v.name.trim() === '') {
    throw new Error(`Variable at index ${i} needs a non-empty string name`);
  }
});

Type guard

function hasValidName(v) {
  return typeof v?.name === 'string' && v.name.length > 0;
}

Try / catch

try {
  validateBrunoEnvironment(env);
} catch (err) {
  if (err.message.includes('missing or invalid name')) {
    env.variables = env.variables.filter(hasValidName);
  }
  throw err;
}

Prevention

When it happens

Trigger: A variable object such as {"value":"v"} (no name), {"name":42} (numeric name), or {"name":""} (empty string triggers the truthy !variable.name check).

Common situations: Stripping names during a transform, exporting from a tool that uses 'key' instead of 'name', or trailing whitespace/empty identifiers after a find-replace.

Related errors


AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13). Data as JSON: /api/errors/2a395896e9054a64. Report an issue: GitHub.