usebruno/bruno · error · BrunoError

Invalid variable at index ${index}: expected an object

Error message

Invalid variable at index ${index}: expected an object

What it means

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.

Source

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

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

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Inspect the variables array at the reported index and replace the primitive/null with a full variable object.
  2. Remove empty slots if the variable is not needed.
  3. Re-export the environment from Bruno rather than hand-editing.

Example fix

// before
"variables": [ "BASE_URL", { "name": "KEY", "value": "v" } ]
// after
"variables": [
  { "name": "BASE_URL", "value": "https://api", "enabled": true },
  { "name": "KEY", "value": "v", "enabled": true }
]
Defensive patterns

Strategy: validation

Validate before calling

env.variables.forEach((v, i) => {
  if (!(v !== null && typeof v === 'object' && !Array.isArray(v))) {
    throw new Error(`Variable at index ${i} is not an object`);
  }
});

Type guard

function isVariableEntry(v) {
  return v !== null && typeof v === 'object' && !Array.isArray(v);
}

Try / catch

try {
  validateBrunoEnvironment(env);
} catch (err) {
  const m = err.message.match(/Invalid variable at index (\d+): expected an object/);
  if (m) env.variables = env.variables.filter(isVariableEntry);
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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