Skip to content

feat(config): Added onFinally hook to middleware - #150

Merged
christerswahn merged 2 commits into
mainfrom
on-finally
Nov 21, 2026
Merged

christerswahn merged 2 commits into
mainfrom
on-finally

Conversation

@christerswahn

@christerswahn christerswahn commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added an onFinally middleware hook that runs after command completion, whether the command succeeds or fails.
    • Added support for combining onFinally with return and error hooks. Errors from the final hook do not replace the command’s result or original error.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Middleware now supports an optional finalization hook that runs after the handler and return or error hook. Command middleware exposes the hook through its composer and factories. Tests cover synchronous and asynchronous callbacks, callback failures, and preservation of command results and exceptions.

Changes: Middleware finalization

Layer / File(s) Summary
Middleware lifecycle
packages/config/lib/src/middleware/middleware_hooks.dart, packages/config/test/middleware/middleware_hooks_test.dart
Middleware runs onFinally after the handler and applicable return or error hook. Tests cover synchronous and asynchronous callbacks, callback failures, and preserved results or exceptions.
Command middleware API
packages/config/lib/src/command/command_middleware.dart, packages/config/test/command/command_middleware_test.dart
CommandMiddlewareComposer and Middlewares.withHooks accept onFinally. Middlewares.onFinally creates middleware with the hook. Tests cover successful and failing commands and combinations with onReturn and onError.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Command
  participant MiddlewareComposer
  participant Handler
  participant Hooks
  Command->>MiddlewareComposer: invoke command middleware
  MiddlewareComposer->>Handler: run command
  Handler-->>MiddlewareComposer: return value or throw error
  MiddlewareComposer->>Hooks: run return or error hook
  Hooks-->>MiddlewareComposer: complete
  MiddlewareComposer->>Hooks: run finalization hook
  Hooks-->>MiddlewareComposer: complete
  MiddlewareComposer-->>Command: return result or propagate original error
Loading

Suggested reviewers: nielsenko

Merge Risk: Minimal · up to 65da7

This adds an optional finalization hook to middleware and command middleware. Existing behavior is unchanged when the hook is not used. Tests cover ordering, results and error preservation, and no concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title 'feat(config): Added onFinally hook to middleware' matches the main change. The PR adds an onFinally hook to the middleware framework (MiddlewareHooks and MiddlewareComposer) and exposes it …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title 'feat(config): Added onFinally hook to middleware' matches the main change. The PR adds an onFinally hook to the middleware framework (MiddlewareHooks and MiddlewareComposer) and exposes it through Middlewares.withHooks and a new Middlewares.onFinally factory. The title is specific and concise, follows a conventional-commit style, and names the affected area (config) and the primary change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 87e4f835-7f60-4b6d-96ec-ed94f64b19c0
Commits

Reviewing files that changed from the base of the PR and between 086da6b and 65da791.

Files selected for processing: 4

  • packages/config/lib/src/command/command_middleware.dart
  • packages/config/lib/src/middleware/middleware_hooks.dart
  • packages/config/test/command/command_middleware_test.dart
  • packages/config/test/middleware/middleware_hooks_test.dart

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

@christerswahn
christerswahn merged commit 5628537 into main Nov 21, 2026
36 checks passed
@christerswahn
christerswahn deleted the on-finally branch November 21, 2026 10:34
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