Skip to content

refactor(auth): make error handling consistent in setSession#2057

Merged
mandarini merged 1 commit into
supabase:masterfrom
7ttp:ref/setsession-error
Jan 26, 2026
Merged

refactor(auth): make error handling consistent in setSession#2057
mandarini merged 1 commit into
supabase:masterfrom
7ttp:ref/setsession-error

Conversation

@7ttp

@7ttp 7ttp commented Jan 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Makes error handling consistent in _setSession by returning errors directly instead of throwing them.

Problem

Line 1902 throws an error from _getUser, while line 1893 returns an error from _callRefreshToken.
This inconsistency within the same function makes the code harder to understand and maintain

Solution

Changed to return the error via _returnResult(), matching the existing pattern used.

Related

Summary by CodeRabbit

Bug Fixes

  • Improved error handling consistency for anonymous sign-in operations.
  • Enhanced session validation error handling to return standardized result formats instead of throwing exceptions.

✏️ Tip: You can customize this high-level summary in your review settings.

@7ttp 7ttp requested review from a team as code owners January 25, 2026 21:31
@coderabbitai

coderabbitai Bot commented Jan 25, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Error handling refactored in GoTrueClient.ts to return standardized results instead of throwing errors in signInAnonymously and _setSession methods, promoting consistent error handling patterns.

Changes

Cohort / File(s) Summary
Error handling consistency
packages/core/auth-js/src/GoTrueClient.ts
signInAnonymously: Changed error path from throwing to returning _returnResult with { user: null, session: null } and error. _setSession: Changed _getUser error handling from throwing to returning standardized result via _returnResult.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Errors now return with grace,
No more throws to chase and trace,
Consistency wins the race,
Single duty in its place! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change—making error handling consistent in _setSession by returning errors via _returnResult instead of throwing them.
Linked Issues check ✅ Passed The PR addresses issue #1699 by standardizing error handling in _setSession to return errors instead of throwing, which aligns with the objective of making setSession consistently return error values.
Out of Scope Changes check ✅ Passed Changes are limited to error handling consistency in _setSession and signInAnonymously, directly addressing the linked issue without introducing unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mandarini mandarini merged commit 74fe0cc into supabase:master Jan 26, 2026
23 checks passed
@7ttp 7ttp deleted the ref/setsession-error branch January 27, 2026 08:40
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.

Violation of Single Responsibility Principle:

2 participants