usebruno/bruno · error · Error

credentialId must be a non-empty string

Error message

credentialId must be a non-empty string

What it means

Thrown by bru.resetOauth2Credential(credentialId) when the credentialId argument is missing, empty, or not a string. The guard at bru.js:288 checks both truthiness and type, rejecting numbers, objects, booleans, and empty/null/undefined values. This protects the OAuth2 credential reset workflow from invalid credential lookups.

Source

Thrown at packages/bruno-js/src/bru.js:289

    return Object.assign({}, this.globalEnvironmentVariables);
  }

  deleteAllGlobalEnvVars() {
    const keys = Object.keys(this.globalEnvironmentVariables);
    if (!keys.length) return;
    for (const key of keys) {
      delete this.globalEnvironmentVariables[key];
    }
    this._globalEnvDirty = true;
  }

  getOauth2CredentialVar(key) {
    return this.interpolate(this.oauth2CredentialVariables[key]);
  }

  resetOauth2Credential(credentialId) {
    if (!credentialId || typeof credentialId !== 'string') {
      throw new Error('credentialId must be a non-empty string');
    }

    if (!this.oauth2CredentialsToReset.includes(credentialId)) {
      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);
  }

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Pass the credential ID as a non-empty string: bru.resetOauth2Credential('my-google-credential').
  2. Verify the credential ID exists in the collection's OAuth2 configuration before calling reset.
  3. If the ID comes from a variable, ensure it is a string: String(credentialId).

Example fix

// before
bru.resetOauth2Credential(credentialId); // credentialId may be undefined or a number

// after
if (typeof credentialId === 'string' && credentialId.length > 0) {
  bru.resetOauth2Credential(credentialId);
}
Defensive patterns

Strategy: type-guard

Validate before calling

function isValidCredentialId(id) {
  return typeof id === 'string' && id.trim() !== '';
}
// before calling: if (isValidCredentialId(id)) bru.resetOauth2Credential(id);

Type guard

function isNonEmptyString(val) {
  return typeof val === 'string' && val.length > 0;
}

Try / catch

try {
  bru.resetOauth2Credential(credentialId);
} catch (e) {
  if (e.message === 'credentialId must be a non-empty string') {
    console.error('Credential ID was missing or not a string');
  }
}

Prevention

When it happens

Trigger: Calling bru.resetOauth2Credential(undefined), bru.resetOauth2Credential(''), bru.resetOauth2Credential(123), or bru.resetOauth2Credential(null). The credential ID must be the exact string identifier of the OAuth2 credential as configured in the collection.

Common situations: Passing a numeric credential index instead of the string ID. Forgetting to set the credential ID variable. Passing the entire credential object instead of its ID string.

Related errors


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