Skip to content

1.4 fix: only rescue JSON decode errors - #771

Draft
dpep wants to merge 1 commit into
ruby-oauth:1-4-stablefrom
dpep:fix/1-4-parse-errors
Draft

dpep wants to merge 1 commit into
ruby-oauth:1-4-stablefrom
dpep:fix/1-4-parse-errors

Conversation

@dpep

@dpep dpep commented Oct 14, 2026 •

Copy link
Copy Markdown

The 1.4 JSON parser is MultiJson.load(body) rescue body, which catches every StandardError and returns the raw body. That's meant for non-JSON bodies served as application/json, but it also hides real failures. With multi_json 1.21 and json 3, MultiJson.load raises ArgumentError (JSON.parse no longer accepts a positional options hash). The parser hands back the raw string, get_token finds no token, and the result reads as invalid credentials: in our case, a login redirect loop.

This rescues only MultiJson::DecodeError, so malformed bodies still fall back to the raw string and anything else raises. DecodeError exists across the gemspec's multi_json ~> 1.3 range (1.3.0 through 1.21.x, aliased to LoadError/ParseError in later versions). get_token needs no change: when no token is built it reads response.parsed again outside its rescue, so the error propagates.

I know 1.4 is EOL. This is here in case another 1.4.x release is ever cut, since 1.4 users hit it as soon as json 3 lands in their bundle.

The JSON parser rescued every StandardError and returned the raw body,
so a broken JSON stack (e.g. multi_json 1.21 with json 3 raising
ArgumentError) looked like a token-less response and get_token reported
invalid credentials. Rescue only MultiJson::DecodeError, which exists
across multi_json ~> 1.3.

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:18
@dpep dpep changed the title 馃悰 1.4: only rescue JSON decode errors only rescue JSON decode errors Oct 14, 2026
@dpep dpep changed the title only rescue JSON decode errors 1.4 fix: only rescue JSON decode errors Oct 14, 2026

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 preserves malformed-body fallback while correctly exposing unexpected parser failures with adequate regression coverage.

0 open findings

What changed in this PR

Narrows JSON error handling so malformed payloads still return raw bodies while unexpected parser failures propagate.

Changes:

  • Rescues only MultiJson::DecodeError.
  • Adds response and token-flow regression tests.
  • Documents the behavior change.
File Description
lib/鈥媜auth2/鈥媟esponse.rb Narrows JSON parser rescue behavior.
spec/鈥媜auth2/鈥媟esponse_spec.rb Tests malformed and unexpected parser errors.
spec/鈥媜auth2/鈥媍lient_spec.rb Verifies parser errors propagate through token retrieval.
CHANGELOG.md Records the fix.

馃 Review effort: Balanced


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

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