{"record":{"id":"b2071668853f1fcf","repo":"usebruno/bruno","slug":"credentialid-must-be-a-non-empty-string","errorCode":null,"errorMessage":"credentialId must be a non-empty string","messagePattern":"credentialId must be a non-empty string","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-js/src/bru.js","lineNumber":289,"sourceCode":"    return Object.assign({}, this.globalEnvironmentVariables);\n  }\n\n  deleteAllGlobalEnvVars() {\n    const keys = Object.keys(this.globalEnvironmentVariables);\n    if (!keys.length) return;\n    for (const key of keys) {\n      delete this.globalEnvironmentVariables[key];\n    }\n    this._globalEnvDirty = true;\n  }\n\n  getOauth2CredentialVar(key) {\n    return this.interpolate(this.oauth2CredentialVariables[key]);\n  }\n\n  resetOauth2Credential(credentialId) {\n    if (!credentialId || typeof credentialId !== 'string') {\n      throw new Error('credentialId must be a non-empty string');\n    }\n\n    if (!this.oauth2CredentialsToReset.includes(credentialId)) {\n      this.oauth2CredentialsToReset.push(credentialId);\n    }\n\n    // Remove matching credential variables so subsequent getOauth2CredentialVar() calls return undefined\n    const prefix = `$oauth2.${credentialId}.`;\n    for (const key of Object.keys(this.oauth2CredentialVariables)) {\n      if (key.startsWith(prefix)) {\n        delete this.oauth2CredentialVariables[key];\n      }\n    }\n  }\n\n  hasVar(key) {\n    return Object.hasOwn(this.runtimeVariables, key);\n  }","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-js/src/bru.js#L271-L307","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the credential ID as a non-empty string: bru.resetOauth2Credential('my-google-credential').","Verify the credential ID exists in the collection's OAuth2 configuration before calling reset.","If the ID comes from a variable, ensure it is a string: String(credentialId)."],"exampleFix":"// before\nbru.resetOauth2Credential(credentialId); // credentialId may be undefined or a number\n\n// after\nif (typeof credentialId === 'string' && credentialId.length > 0) {\n  bru.resetOauth2Credential(credentialId);\n}","handlingStrategy":"type-guard","validationCode":"function isValidCredentialId(id) {\n  return typeof id === 'string' && id.trim() !== '';\n}\n// before calling: if (isValidCredentialId(id)) bru.resetOauth2Credential(id);","typeGuard":"function isNonEmptyString(val) {\n  return typeof val === 'string' && val.length > 0;\n}","tryCatchPattern":"try {\n  bru.resetOauth2Credential(credentialId);\n} catch (e) {\n  if (e.message === 'credentialId must be a non-empty string') {\n    console.error('Credential ID was missing or not a string');\n  }\n}","preventionTips":["Pass the credential ID as a string, not a number or object.","Verify the credential exists in the collection's OAuth2 configuration first.","Use typeof credentialId === 'string' as a guard."],"tags":["oauth2","credentials","validation","reset"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}