usebruno/bruno · error · Error
Creating a variable without specifying a name is not allowed
Error message
Creating a variable without specifying a name is not allowed.
What it means
Thrown by bru.setVar(key, value) when the key argument is falsy. This guards the runtime (request-scoped) variable scope. The check at bru.js:310 rejects undefined, null, empty string, 0, and false before validating the key format and writing to runtimeVariables.
Source
Thrown at packages/bruno-js/src/bru.js:311
this.oauth2CredentialsToReset.push(credentialId);
}
// Remove matching credential variables so subsequent getOauth2CredentialVar() calls return undefined
const prefix = `$oauth2.${credentialId}.`;
for (const key of Object.keys(this.oauth2CredentialVariables)) {
if (key.startsWith(prefix)) {
delete this.oauth2CredentialVariables[key];
}
}
}
hasVar(key) {
return Object.hasOwn(this.runtimeVariables, key);
}
setVar(key, value) {
if (!key) {
throw new Error('Creating a 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, "-", "_", "."'
);
}
if (!Object.hasOwn(this.runtimeVariables, key) || !isEqual(this.runtimeVariables[key], value)) {
this.runtimeVariables[key] = value;
this._runtimeVarsDirty = true;
}
}
getVar(key) {
if (variableNameRegex.test(key) === false) {
throw new Error(View on GitHub (pinned to 9bdd81c7bd)
Solutions
- Pass a non-empty string literal as the key: bru.setVar('userId', value).
- Guard the call with a truthiness check on the key.
- Use a default key when the dynamic source may be empty: bru.setVar(key || 'default', value).
Example fix
// before
for (const item of items) {
bru.setVar(item.name, item.value); // item.name may be undefined
}
// after
for (const item of items) {
if (item.name) {
bru.setVar(item.name, item.value);
}
} Defensive patterns
Strategy: validation
Validate before calling
function isValidVarKey(key) {
return typeof key === 'string' && key.length > 0;
}
// before calling: if (isValidVarKey(key)) bru.setVar(key, value); Try / catch
try {
bru.setVar(key, value);
} catch (e) {
if (e.message.includes('without specifying a name')) {
console.error('Runtime variable key was empty or missing');
}
} Prevention
- Always pass a non-empty string as the key.
- Guard dynamic keys from loops or response data with a truthiness check.
- Use a fallback key when the source may be empty.
When it happens
Trigger: Calling bru.setVar(undefined, 'value'), bru.setVar('', 'value'), or bru.setVar(null, 'value'). This is common when the key is derived from response data that is not present or from a loop variable that is empty.
Common situations: Using a response field as the key name when the field is absent. Iterating over a list with empty entries and using each as a key. Forgetting to pass the first argument.
Related errors
- Creating a env variable without specifying a name is not all
- Workspace path not found
- Invalid Git URL
- Invalid environment: expected an object
- Invalid environment: missing or invalid variables array
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/4954bbd8dfb20655.
Report an issue: GitHub.