usebruno/bruno · error · Error
Creating a env variable without specifying a name is not all
Error message
Creating a env variable without specifying a name is not allowed.
What it means
Thrown by bru.setEnvVar(key, value) when the key argument is falsy (undefined, null, empty string, 0, false). The guard at bru.js:199 checks !key and rejects any falsy value before proceeding to validate the key format and set the variable in the environment scope.
Source
Thrown at packages/bruno-js/src/bru.js:200
getEnvName() {
return this.envVariables.__name__;
}
getProcessEnv(key) {
return this.processEnvVars[key];
}
hasEnvVar(key) {
return Object.hasOwn(this.envVariables, key);
}
getEnvVar(key) {
return this.interpolate(this.envVariables[key]);
}
setEnvVar(key, value) {
if (!key) {
throw new Error('Creating a env variable without specifying a name is not allowed.');
}
if (variableNameRegex.test(key) === false) {
throw new Error(
`Variable name: "${key}" contains invalid characters! Names must only contain alpha-numeric characters, "-", "_", "."`
);
}
// Deep-equal compare so object/array writes that mutate in place
// (e.g. `const c = bru.getEnvVar('cfg'); c.port = 4000; bru.setEnvVar('cfg', c);`)
// still flip the dirty flag — strict `!==` returned false for same-reference writes.
if (!Object.hasOwn(this.envVariables, key) || !isEqual(this.envVariables[key], value)) {
this.envVariables[key] = value;
this._envDirty = true;
}
}
deleteEnvVar(key) {View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Provide a non-empty, static string literal as the key: bru.setEnvVar('token', value).
- Validate the key is a non-empty string before calling setEnvVar.
- Use a fallback if the key source may be empty: bru.setEnvVar(key || 'default', value).
Example fix
// before
const key = res.getBody()?.name; // may be undefined
bru.setEnvVar(key, 'active');
// after
const key = res.getBody()?.name;
if (key) {
bru.setEnvVar(key, 'active');
} Defensive patterns
Strategy: validation
Validate before calling
function isValidEnvVarKey(key) {
return typeof key === 'string' && key.length > 0;
}
// before calling: if (isValidEnvVarKey(key)) bru.setEnvVar(key, value); Try / catch
try {
bru.setEnvVar(key, value);
} catch (e) {
if (e.message.includes('without specifying a name')) {
console.error('Environment variable key was empty or missing');
}
} Prevention
- Always pass a non-empty string literal as the key argument.
- Guard dynamic keys with a truthiness check.
- Use a fallback key when the source may be empty.
When it happens
Trigger: Calling bru.setEnvVar(undefined, 'value'), bru.setEnvVar('', 'value'), bru.setEnvVar(null, 'value'), or passing a variable name computed dynamically that evaluates to empty (e.g., bru.setEnvVar(req.getUrl(), 'value') when the URL is empty).
Common situations: Using a dynamically computed key from request data that may be empty (e.g., extracting a header that is not present). Forgetting to pass the key argument. Using a variable that has not been initialized as the key.
Related errors
- Variable name: "${key}" contains invalid characters! Names m
- Creating a variable without specifying a name is not allowed
- Workspace path not found
- Invalid Git URL
- Invalid environment: expected an object
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/a60d1df8b8ace542.
Report an issue: GitHub.