google-gemini / google-gemini/gemini-cli
bug: isAuthenticationError falsely matches port numbers or non-auth messages containing '401'
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### What happened?
In `packages/core/src/utils/errors.ts`, the `isAuthenticationError` helper checks if an error message contains the string `"401"`. However, this check is too broad. If a connection failure or another error message contains a port number or line number with the substring `"401"` (e.g. `Error connecting to http://localhost:4012`, `exit status 4010`, or `error at line 401`), `isAuthenticationError` will return `true`.
This causes the CLI to falsely identify these errors as authentication failures, triggering unnecessary OAuth fallback logic or displaying misleading diagnostics such as `"requires authentication using: /mcp auth..."` instead of showing the actual connection or logic failure.
### What did you expect to happen?
`isAuthenticationError` should only return `true` for actual HTTP 401 Unauthorized errors. It should use a more precise regular expression or check for status code properties specifically.
### Client information
Platform: Windows/macOS/Linux
Core version: 0.51.0
### Anything else we need to know?
The code in `packages/core/src/utils/errors.ts`:
```typescript
const message = getErrorMessage(error);
if (message.includes('401')) {
return true;
}
```
A better approach would be to check using word boundaries or a more specific regex:
```typescript
if (/\b401\b/.test(message)) {
return true;
}
```
Contributor guide
Research direction
Start in packages/core/src/utils/errors.ts and inspect the isAuthenticationError helper and its getErrorMessage input. Exercise it with actual 401 responses and messages containing values such as 4012, 4010, or line 401. Done means genuine HTTP 401 errors are recognized while unrelated messages are not, without triggering misleading CLI authentication handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- authentication, cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100