Skip to content

fix(types): keep failure context strict - #78

Merged
yordis merged 2 commits into
mainfrom
yordis/fix-failure-context-type
Apr 15, 2026
Merged

yordis merged 2 commits into
mainfrom
yordis/fix-failure-context-type

Conversation

@yordis

@yordis yordis commented Apr 15, 2026 •

Copy link
Copy Markdown
Member
  • Preserves the production failure-context contract instead of weakening it to accommodate invalid partial fixtures
  • Keeps Dialyzer aligned with the runtime constructor while moving tests toward valid failure-context values rather than expanding the public type surface

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@cursor

cursor Bot commented Apr 15, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Low risk: type/spec enforcement and test fixture updates only, with no changes to runtime error-handling logic beyond struct construction requirements.

Overview
Updates Commanded.Event.FailureContext to use Commanded.Application.app_ref() for :application and to @enforce_keys required fields (:application, :handler_name, :context, :metadata).

Adjusts ErrorHandler tests to build complete FailureContext structs via a helper (including realistic metadata) instead of partially populated %FailureContext{} values, keeping tests aligned with the stricter struct contract.

Reviewed by Cursor Bugbot for commit 56551f2. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Apr 15, 2026 •

Copy link
Copy Markdown

Walkthrough

The FailureContext struct type definition updates the :application field type from Commanded.Application.t() to Commanded.Application.app_ref() and introduces compile-time enforcement requiring :application, :handler_name, :context, and :metadata fields. Test code is refactored to construct FailureContext via a helper function with populated default values.

Changes

Cohort / File(s) Summary
Struct Type Definition
lib/commanded/event/failure_context.ex
Updated :application field type annotation from Commanded.Application.t() to Commanded.Application.app_ref() and added @enforce_keys directive for four required fields.
Test Helper Refactoring
test/commanded/event/error_handler_test.exs
Converted direct FailureContext struct construction to a parameterized helper function failure_context/1 with default argument, providing sensible defaults for all enforced fields across test cases.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Fields now guarded, compile-time strong,
Application's type rights a checking wrong,
Tests hop happily with helpers in place,
FailureContext shines with grace!
Defaults flow free, refactoring's delight,
All struct construction now just right! 🐇

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'fix(types): keep failure context strict' accurately reflects the main change—enforcing stricter type definitions and struct key constraints for FailureContext to maintain type safety.
Description check ✅ Passed The description clearly relates to the changeset, explaining that the changes preserve the production failure-context contract by enforcing key requirements and aligning Dialyzer with runtime behavior.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch yordis/fix-failure-context-type

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.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis changed the title fix(types): reflect partial failure context construction fix(types): keep failure context strict Apr 15, 2026
@yordis
yordis merged commit 47db0d2 into main Apr 15, 2026
7 checks passed
@yordis
yordis deleted the yordis/fix-failure-context-type branch April 15, 2026 03:15
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.

1 participant