oauth: return error instead of (nil, nil) from getServerMetadata (#903) - #904
Conversation
When metadata discovery hits a non-2xx response, fetchMetadataFromURL returns (nil, nil), leaving getServerMetadata returning (nil, nil) — no metadata and no error. Callers (RegisterClient, token/auth URL builders) then dereferenced the nil *AuthServerMetadata and panicked. Return an explicit error instead. Fixes mark3labs#903.
|
Connected to Huly®: MCP_G-468 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughgetServerMetadata now records and returns a non-nil error when discovery finishes without producing metadata (avoiding a (nil, nil) return). New regression tests exercise a 404 metadata discovery endpoint and assert GetServerMetadata returns an error and RegisterClient does not panic. ChangesOAuth nil metadata fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes a panic path in OAuth metadata discovery by ensuring callers receive an explicit error when discovery yields no metadata, and adds regression tests to prevent returning (nil, nil).
Changes:
- Add regression tests covering unavailable metadata discovery and ensuring
RegisterClientdoesn’t panic. - Update
getServerMetadatato return a non-nil error whenserverMetadatais stillnil.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| client/transport/oauth_nil_metadata_test.go | Adds regression tests for the “nil metadata + nil error” discovery failure mode. |
| client/transport/oauth.go | Surfaces an explicit error when metadata discovery returns no metadata to prevent nil deref panics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Record the 'metadata unavailable' error once in metadataFetchErr inside once.Do (consistent cached failure, no per-call allocation) and include the discovery target in the message. Keep a defensive tail check so a concurrent once swap can never reintroduce a (nil, nil) return.
Fixes #903. getServerMetadata returned (nil, nil) on a non-2xx discovery response, so callers (RegisterClient, token/auth URL builders) dereferenced a nil *AuthServerMetadata and panicked. It now returns an explicit error instead; callers already handle the error path. Adds regression tests covering getServerMetadata and RegisterClient.
Summary by CodeRabbit