{"record":{"id":"5394137e2880ba18","repo":"usebruno/bruno","slug":"invalid-environment-expected-an-object","errorCode":null,"errorMessage":"Invalid environment: expected an object","messagePattern":"Invalid environment: expected an object","errorType":"validation","errorClass":"BrunoError","httpStatus":null,"severity":"error","filePath":"packages/bruno-app/src/utils/importers/bruno-environment.js","lineNumber":6,"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","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-app/src/utils/importers/bruno-environment.js#L1-L24","documentation":"Thrown by validateBrunoEnvironment() at the top of the Bruno environment import pipeline. It fires when the parsed environment value is not a non-null object (it is null, undefined, a primitive, or an array). This is the first structural gate before variables are inspected.","triggerScenarios":"Calling importBrunoEnvironment / processEnvironmentData with a parsed JSON document whose environment entry is null, a string, a number, a boolean, or an array (e.g. a top-level JSON array element that is a primitive, or an empty file parsed to null).","commonSituations":"Empty or whitespace-only .json file, JSON.parse returning a primitive (e.g. file content is just \"true\" or \"42\"), exporting a single environment as a bare array, or hand-editing an environment file so a variable slot is null.","solutions":["Open the imported file and confirm the top-level value (or each element of the environments array) is a JSON object with curly braces.","If the file is empty or null, regenerate it via Bruno's Export Environment action.","Run JSON.parse(content) in a console and verify typeof result === 'object' && result !== null && !Array.isArray(result) before importing.","Validate the file against Bruno's environment schema before import."],"exampleFix":"// before: file content is 'null' or '\"staging\"'\n// after: file content is\n{\n  \"name\": \"Staging\",\n  \"variables\": []\n}","handlingStrategy":"validation","validationCode":"function isPlainObject(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}\n// before calling importBrunoEnvironment / validateBrunoEnvironment:\nif (!isPlainObject(env)) throw new Error('Environment must be a plain object');","typeGuard":"function isBrunoEnvironment(env) {\n  return env !== null && typeof env === 'object' && !Array.isArray(env);\n}","tryCatchPattern":"try {\n  validateBrunoEnvironment(env);\n} catch (err) {\n  if (err.message.startsWith('Invalid environment: expected an object')) {\n    // surface to user that the file root is not an object\n  }\n  throw err;\n}","preventionTips":["Validate parsed JSON root is a plain object before passing to the importer.","Regenerate environment files via Bruno's Export rather than hand-editing.","Lint environment files with a JSON schema validator in CI."],"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"}