Skip to content

Conversation

leynos
Copy link
Owner

@leynos leynos commented Jun 19, 2025

Summary

  • implement Message<T> and ConnectionInfo extractors
  • extend SharedState<T> error handling
  • document custom extractor usage
  • add tests for extractor functionality
  • clarify current limitations in README

Testing

  • make fmt
  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_6853d8dc92588322bce4f3c5a60cf379

Summary by Sourcery

Implement typed extractors for deserializing message payloads and exposing connection metadata, extend shared state error handling, update documentation on custom extractors and library limitations, and add tests for extractor functionality.

New Features:

  • Add Message extractor for payload deserialization
  • Introduce ConnectionInfo extractor for peer address metadata

Enhancements:

  • Extend ExtractError with a Deserialize variant and implement its source
  • Enhance SharedState extractor error handling for missing and decode failures

Documentation:

  • Document custom extractor usage and update README with examples
  • Add extractor class diagram and expand design guide
  • Clarify experimental limitations in README

Tests:

  • Add tests for Message, ConnectionInfo, and SharedState extractors

Summary by CodeRabbit

  • New Features
    • Introduced new extractors for message payload deserialization and connection metadata access, including Message<T> and ConnectionInfo.
  • Bug Fixes
    • Improved error reporting for payload deserialization failures.
  • Documentation
    • Expanded documentation with detailed explanations and diagrams for custom extractors and their usage.
    • Enhanced README with a new section on custom extractors and updated information on current limitations.
  • Tests
    • Added unit tests to validate extractor behaviour and error handling.

Copy link
Contributor

sourcery-ai bot commented Jun 19, 2025

Reviewer's Guide

This PR implements two new extractor types (Message and ConnectionInfo), enhances SharedState extractor error handling by propagating decode errors, updates documentation with custom extractor usage and current limitations, and adds comprehensive tests for extractor functionality.

Class diagram for new and updated extractor types

classDiagram
    class FromMessageRequest {
        <<trait>>
        +from_message_request(req: &MessageRequest, payload: &mut Payload) Result<Self, Self::Error>
        +Error
    }
    class Message~T~ {
        +Message(T)
        +into_inner() T
        +deref() &T
    }
    class ConnectionInfo {
        +peer_addr: Option<SocketAddr>
        +peer_addr() Option<SocketAddr>
    }
    class SharedState~T~ {
        +deref() &T
    }
    class ExtractError {
        +MissingState(&'static str)
        +Deserialize(DecodeError)
    }
    FromMessageRequest <|.. Message
    FromMessageRequest <|.. ConnectionInfo
    FromMessageRequest <|.. SharedState
    SharedState --> ExtractError
    ExtractError o-- DecodeError
    Message o-- T
    SharedState o-- T
    ConnectionInfo o-- SocketAddr
Loading

File-Level Changes

Change Details Files
Enhance SharedState extractor error handling
  • add Deserialize variant to ExtractError
  • implement Error::source to propagate underlying decoding errors
src/extractor.rs
Introduce new extractor types
  • define Message with Deref and into_inner
  • implement FromMessageRequest for Message deserializing payload
  • define ConnectionInfo for peer metadata
  • implement FromMessageRequest for ConnectionInfo
src/extractor.rs
Update documentation for custom extractors and limitations
  • document custom extractor usage in README
  • clarify experimental limitations in README
  • add extractor class diagram to design guide
README.md
docs/rust-binary-router-library-design.md
Add tests for extractor functionality
  • message extractor parse and advance test
  • connection info peer address test
  • shared state success and missing state error tests
tests/extractor.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

coderabbitai bot commented Jun 19, 2025

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.

Walkthrough

The changes introduce new extractor types and error handling improvements to the extraction framework, update documentation to explain custom extractors, and add tests for the new extractors. The extractor system now supports deserialising payloads into message types and extracting connection metadata, with enhanced error reporting for deserialisation failures.

Changes

File(s) Change Summary
README.md Added documentation on custom extractors, updated code examples, clarified limitations section.
src/extractor.rs Added Message<T> and ConnectionInfo extractors, new deserialisation error variant, improved docs.
tests/extractor.rs Added unit tests for message extraction and connection info extraction.
docs/rust-binary-router-library-design.md Added Mermaid class diagram and refined extractor system documentation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant Extractor
    participant Handler

    Client->>Server: Send message (payload + metadata)
    Server->>Extractor: Call FromMessageRequest for each handler param
    Extractor->>Extractor: Deserialize payload (Message<T>)
    Extractor->>Extractor: Extract peer address (ConnectionInfo)
    Extractor->>Handler: Provide extracted params
    Handler->>Server: Process with extracted data
Loading

Possibly related PRs

  • Implement trait foundations #8: Foundational extractor abstractions and traits that this PR extends with new extractor types and error handling.
  • Fix bincode trait bounds #44: Updates the Message trait to require BorrowDecode, which is directly relied upon by the new Message<T> extractor for deserialisation in this PR.
  • Add shared state container #75: Adds shared state extractor and related app data handling, complementing the new extractors introduced here.

Poem

In burrows deep, new extractors bloom,
Decoding messages, dispelling gloom.
With peer address found and payload read,
The tests all pass, the docs are fed.
A hop and a skip, the framework grows—
Where rabbit logic nimbly flows! 🐇

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch codex/define-extractors-and-implement-frommessagerequest

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

Absence of Expected Change Pattern

  • wireframe/src/extractor.rs is usually changed with: wireframe/src/middleware.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes - here's some feedback:

  • Consider unifying the Message<T> extractor’s error type with the new ExtractError::Deserialize variant so handlers always use a single error enum rather than exposing bincode::DecodeError directly.
  • The placeholder doc link 【F:docs/rust-binary-router-library-design.md†L842-L858】 looks broken—please replace it with a valid intra-repo or external URL so readers can follow the example.
  • You’ve added tests for Message and ConnectionInfo—consider adding a test for the SharedState<T> extractor (including the missing-state error path) to cover all built-in extractors.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider unifying the `Message<T>` extractor’s error type with the new `ExtractError::Deserialize` variant so handlers always use a single error enum rather than exposing `bincode::DecodeError` directly.
- The placeholder doc link `【F:docs/rust-binary-router-library-design.md†L842-L858】` looks broken—please replace it with a valid intra-repo or external URL so readers can follow the example.
- You’ve added tests for `Message` and `ConnectionInfo`—consider adding a test for the `SharedState<T>` extractor (including the missing-state error path) to cover all built-in extractors.

## Individual Comments

### Comment 1
<location> `src/extractor.rs:205` </location>
<code_context>
 }
+
+/// Extractor that deserializes the message payload into `T`.
+pub struct Message<T>(T);
+
+impl<T> Message<T> {
</code_context>

<issue_to_address>
The module is missing a containing item comment (`//!`).

Please add a `//!` comment at the top of the file to describe the module's purpose, as required by the review instructions.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c09669d and e1b6bac.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • src/extractor.rs (4 hunks)
  • tests/extractor.rs (1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[uncategorized] ~153-~153: Use a comma before ‘so’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...rimental. Release builds fail to compile so the library cannot be used accidentally...

(COMMA_COMPOUND_SENTENCE_2)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test
🔇 Additional comments (8)
src/extractor.rs (5)

14-16: Well-structured imports for new functionality.

The imports properly support the new extractor types and error handling enhancements.


72-77: Excellent documentation enhancement.

The expanded trait documentation clearly explains how extractors integrate with handler parameters and their role in sharing common parsing logic.


146-166: Proper error handling with chaining support.

The new Deserialize error variant correctly implements error chaining via the source() method, allowing access to underlying DecodeError details for debugging.


204-233: Well-designed generic extractor implementation.

The Message<T> extractor properly:

  • Uses the WireMessage trait bound for type safety
  • Advances the payload cursor to track consumption
  • Provides both Deref and into_inner() for flexible access patterns
  • Returns specific DecodeError for precise error reporting

235-258: Clean and appropriate connection metadata extractor.

The ConnectionInfo extractor correctly uses std::convert::Infallible as the error type since peer address extraction cannot fail, demonstrating proper type-level guarantees.

README.md (1)

109-148: Excellent documentation addition for custom extractors.

The new section provides clear guidance on implementing custom extractors with a practical example. The explanation of how extractors integrate with handler parameters is particularly helpful for developers.

tests/extractor.rs (2)

11-23: Comprehensive test for Message extractor.

The test properly verifies both deserialization correctness and payload advancement, ensuring the extractor behaves correctly in the extraction pipeline.


25-35: Well-focused test for ConnectionInfo extractor.

The test correctly validates peer address extraction from request metadata, covering the core functionality of the connection info extractor.

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

Absence of Expected Change Pattern

  • wireframe/src/extractor.rs is usually changed with: wireframe/src/middleware.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

Absence of Expected Change Pattern

  • wireframe/src/extractor.rs is usually changed with: wireframe/src/middleware.rs

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@leynos
Copy link
Owner Author

leynos commented Jun 19, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/extractor.rs:202` </location>
<code_context>
 }
+
+/// Extractor that deserializes the message payload into `T`.
+pub struct Message<T>(T);
+
+impl<T> Message<T> {
</code_context>

<issue_to_address>
The module is missing a containing item comment (`//!`).

Please add a `//!` comment at the top of the file to describe the purpose of this module, as required by the review instructions.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes - here's some feedback:

  • Derive Debug (and optionally Clone) for the new Message and ConnectionInfo extractors so that they’re easier to inspect in logs and tests.
  • Consider renaming the ExtractError::Deserialize variant (e.g. to InvalidPayload or DecodeError) to more clearly reflect its purpose in the extractor context.
  • When reporting MissingState, use std::any::type_name::<T>() to include the fully qualified type name for clearer error messages.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Derive Debug (and optionally Clone) for the new Message<T> and ConnectionInfo extractors so that they’re easier to inspect in logs and tests.
- Consider renaming the ExtractError::Deserialize variant (e.g. to `InvalidPayload` or `DecodeError`) to more clearly reflect its purpose in the extractor context.
- When reporting MissingState, use `std::any::type_name::<T>()` to include the fully qualified type name for clearer error messages.

## Individual Comments

### Comment 1
<location> `src/extractor.rs:202` </location>
<code_context>
 }
+
+/// Extractor that deserializes the message payload into `T`.
+pub struct Message<T>(T);
+
+impl<T> Message<T> {
</code_context>

<issue_to_address>
The module is missing a containing item comment (`//!`).

Please add a `//!` comment at the top of the file to describe the purpose of this module, as required by the review instructions.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/extractor.rs:202` </location>
<code_context>
 }
+
+/// Extractor that deserializes the message payload into `T`.
+pub struct Message<T>(T);
+
+impl<T> Message<T> {
</code_context>

<issue_to_address>
The module is missing a containing item comment (`//!`).

Please add a `//!` comment at the top of the file to describe the module's purpose, as required by the review instructions.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos
Copy link
Owner Author

leynos commented Jun 19, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jun 19, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai bot added a commit that referenced this pull request Jun 19, 2025
…erequest`

Docstrings generation was requested by @leynos.

* #79 (comment)

The following files were modified:

* `src/extractor.rs`
* `tests/extractor.rs`
Copy link
Contributor

coderabbitai bot commented Jun 19, 2025

Note

Generated docstrings for this pull request at #83

…erequest` (#83)

* 📝 Add docstrings to `codex/define-extractors-and-implement-frommessagerequest`

Docstrings generation was requested by @leynos.

* #79 (comment)

The following files were modified:

* `src/extractor.rs`
* `tests/extractor.rs`

* Reorder attributes after doc comments (#84)

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Leynos <leynos@troubledskies.net>
@leynos leynos merged commit e70d2b1 into main Jun 20, 2025
5 checks passed
@leynos leynos deleted the codex/define-extractors-and-implement-frommessagerequest branch June 20, 2025 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant