Skip to content

fix: honor explicit msg in FgaError constructor#325

Open
aaguiarz wants to merge 3 commits intomainfrom
fix/issue-324-fgaerror-msg-precedence
Open

fix: honor explicit msg in FgaError constructor#325
aaguiarz wants to merge 3 commits intomainfrom
fix/issue-324-fgaerror-msg-precedence

Conversation

@aaguiarz
Copy link
Member

@aaguiarz aaguiarz commented Feb 16, 2026

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
Copy link

dosubot bot commented Feb 16, 2026

Related Documentation

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

How did I do? Any feedback?  Join Discord

@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

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
Copy link

codecov-commenter commented Feb 16, 2026

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.

Copy link
Contributor

Copilot AI left a comment

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.

const err = new FgaError(new Error("wrapped-error"), "explicit-message");

expect(err.message).toBe("explicit-message");
});
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

Consider adding additional test cases to ensure comprehensive coverage of the FgaError constructor behavior. Suggested scenarios:

  1. When msg is undefined/not provided, verify the error message is derived from err parameter
  2. When err is a string, verify the message uses that string
  3. When err is an Error object without msg, verify the default "FGA Error: ..." format is used
  4. Edge case: when msg is an empty string, verify it's used (since ?? only treats null/undefined as nullish)

These additional tests would help prevent future regressions and document the expected behavior more thoroughly.

Suggested change
});
});
test("should derive message from err when msg is not provided and err is a string", () => {
const err = new FgaError("string-error");
// Expect the message to be derived from the string err parameter
expect(err.message).toBe("string-error");
});
test('should use default "FGA Error: ..." format when err is an Error and msg is not provided', () => {
const underlying = new Error("inner-error");
const err = new FgaError(underlying);
// Expect the default FGA Error formatting to be used
expect(err.message).toBe("FGA Error: inner-error");
});
test("should use empty string msg when provided (edge case for nullish coalescing)", () => {
const err = new FgaError("ignored-error", "");
// Empty string should be respected, not replaced by a derived or default message
expect(err.message).toBe("");
});

Copilot uses AI. Check for mistakes.
Copy link

@coderabbitai coderabbitai bot left a comment

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
Copy link
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.

Copy link
Contributor

Copilot AI left a comment

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.

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

2 participants