Skip to content

🐛 Raise parse errors on legacy extract path - #770

Open
dpep wants to merge 3 commits into
ruby-oauth:mainfrom
dpep:fix/legacy-extract-parse-errors
Open

dpep wants to merge 3 commits into
ruby-oauth:mainfrom
dpep:fix/legacy-extract-parse-errors

Conversation

@dpep

@dpep dpep commented Oct 14, 2026 •

Copy link
Copy Markdown

Client#build_access_token_legacy calls response.parsed inside its catch-all rescue, so a body that fails to parse looks the same as a response with no token. With raise_errors: true you get a generic OAuth2::Error, and with raise_errors: false you get nil. Either way the parse error is lost.

This parses before the rescue, so parse errors propagate, which matches the default (non-legacy) get_token path. Errors raised by the extract proc itself are still rescued, so nil and empty bodies behave the same as before.

I know the inline comment says it isn't worth changing deprecated code. It's a small change, though, and anyone still on extract_access_token (often a holdover from 1.4.x) hits exactly this: a broken dependency or malformed body shows up as an auth failure instead of a stack trace.

build_access_token_legacy parsed the response inside its catch-all
rescue, so a body that failed to parse looked the same as a token-less
response. Parse before the rescue so parse errors propagate; errors
raised by the extract proc are still rescued.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused implementation correctly preserves extractor handling while allowing parsing failures to propagate.

0 open findings

What changed in this PR

Ensures legacy access-token extraction propagates response parsing failures consistently with the standard token path.

Changes:

  • Parses responses before rescuing legacy extractor errors.
  • Updates invalid-JSON coverage.
  • Documents the fix in the changelog.
File Description
lib/​oauth2/​client.rb Separates parsing from legacy extraction error handling.
spec/​oauth2/​client_spec.rb Verifies parse errors propagate through legacy extraction.
CHANGELOG.md Records the corrected behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dpep
dpep marked this pull request as ready for review October 14, 2026 20:07
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 20:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused implementation matches the stated behavior and includes appropriate regression coverage.

0 open findings

🧠 Review effort: Balanced

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 20:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused implementation matches the intended behavior and is adequately covered by regression tests.

0 open findings

🧠 Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants