Skip to content

fix: honor explicit msg in FgaError constructor#325

Merged
rhamzeh merged 3 commits into
mainfrom
fix/issue-324-fgaerror-msg-precedence
Feb 27, 2026
Merged

fix: honor explicit msg in FgaError constructor#325
rhamzeh merged 3 commits into
mainfrom
fix/issue-324-fgaerror-msg-precedence

Conversation

@aaguiarz

@aaguiarz aaguiarz commented Feb 16, 2026

Copy link
Copy Markdown
Member

Summary

Fixes operator precedence in FgaError constructor so a provided msg is actually used.

Changes

  • Added regression test asserting explicit message precedence
  • Switched constructor expression to use explicit nullish-coalescing grouping

Potential Breaking Change

  • new FgaError(err, msg) now uses msg whenever it is not null/undefined (including empty string).
  • Consumers that relied on the previous buggy message content (for string matching in tests/log parsing) may observe different error messages.

Fixes #324

Copilot AI review requested due to automatic review settings February 16, 2026 18:50
@aaguiarz
aaguiarz requested a review from a team as a code owner February 16, 2026 18:50
@dosubot

dosubot Bot commented Feb 16, 2026

Copy link
Copy Markdown

Related Documentation

Checked 8 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@coderabbitai

coderabbitai Bot commented Feb 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The FgaError constructor is fixed to use nullish coalescing (\?\?) instead of logical OR (||), resolving an operator precedence bug that prevented explicit error messages from being used. A test is added to verify the corrected behavior.

Changes

Cohort / File(s) Summary
FgaError Constructor Fix
errors.ts
Changed message selection from logical OR to nullish coalescing, correcting operator precedence logic so explicit messages take precedence over derived messages from wrapped errors.
FgaError Tests
tests/errors.test.ts
Added unit test verifying FgaError respects and uses explicit messages when provided to the constructor.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing the FgaError constructor to honor an explicit msg parameter.
Linked Issues check ✅ Passed The PR directly addresses issue #324 by switching from || to ?? for nullish coalescing, ensuring explicit msg takes precedence and includes a regression test.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the operator precedence issue in FgaError and adding a regression test; no extraneous modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-324-fgaerror-msg-precedence

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.

@codecov-commenter

codecov-commenter commented Feb 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.67%. Comparing base (a7090e2) to head (e81ca75).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #325   +/-   ##
=======================================
  Coverage   89.67%   89.67%           
=======================================
  Files          25       25           
  Lines        1492     1492           
  Branches      279      279           
=======================================
  Hits         1338     1338           
  Misses         94       94           
  Partials       60       60           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Pull request overview

This PR fixes an operator precedence bug in the FgaError constructor where a provided msg parameter was being ignored due to incorrect operator precedence with the logical OR (||) operator.

Changes:

  • Fixed FgaError constructor to use nullish coalescing (??) with proper grouping instead of logical OR
  • Added regression test to verify explicit message parameter is honored
  • Removed unnecessary type assertion (as string) that became redundant after the fix

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
errors.ts Fixed operator precedence bug in FgaError constructor by switching from `
tests/errors.test.ts Added regression test asserting that explicit msg parameter takes precedence over derived error message

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/errors.test.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/errors.test.ts (1)

1-11: Good regression test for the reported bug.

The test correctly validates the core fix. Consider adding a few more edge cases to lock down the full behavior matrix:

💡 Suggested additional test cases
+    test("should derive message from string err when msg is not provided", () => {
+      const err = new FgaError("string-error");
+      expect(err.message).toBe("string-error");
+    });
+
+    test("should derive message from Error err when msg is not provided", () => {
+      const err = new FgaError(new Error("inner"));
+      expect(err.message).toBe("FGA Error: inner");
+    });
+
+    test("should preserve empty string msg", () => {
+      const err = new FgaError(new Error("inner"), "");
+      expect(err.message).toBe("");
+    });

@aaguiarz

aaguiarz commented Feb 16, 2026

Copy link
Copy Markdown
Member Author

Addressed the review suggestion about expanding constructor behavior coverage.

Implemented in commit e81ca75:

  • added tests for string err without msg
  • added tests for Error err without msg
  • added test for empty-string msg edge case

All tests/errors.test.ts cases pass locally after this change.

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rhamzeh
rhamzeh enabled auto-merge February 27, 2026 03:28
@rhamzeh
rhamzeh added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit 5470381 Feb 27, 2026
32 checks passed
@rhamzeh
rhamzeh deleted the fix/issue-324-fgaerror-msg-precedence branch February 27, 2026 03:30
@openfga-releaser-bot openfga-releaser-bot Bot mentioned this pull request Apr 29, 2026
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.

fix: FgaError constructor ignores explicit msg due operator precedence

4 participants