Skip to content

Replace unwraps with expect#225

Merged
leynos merged 10 commits intomainfrom
codex/replace-.unwrap-with-.expect
Aug 3, 2025
Merged

Replace unwraps with expect#225
leynos merged 10 commits intomainfrom
codex/replace-.unwrap-with-.expect

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 31, 2025

Summary

  • replace .unwrap() calls with .expect() across tests and code
  • add meaningful error messages for each .expect()

Testing

  • make fmt
  • make lint
  • make test

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

Summary by Sourcery

Replace .unwrap() calls with .expect() throughout the codebase and tests, adding descriptive error messages for improved debugging

Enhancements:

  • Replace unwrap calls in production code (e.g., queue creation and unbounded rate limit) with expect and custom error messages

Tests:

  • Update tests to use expect with meaningful messages instead of unwrap for operations like push, recv, socket binding, encoding/decoding, actor execution, and middleware calls

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 31, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 23a2bbe and 9355c36.

📒 Files selected for processing (6)
  • examples/metadata_routing.rs (0 hunks)
  • src/connection.rs (2 hunks)
  • src/push.rs (2 hunks)
  • src/server.rs (11 hunks)
  • tests/connection_actor.rs (16 hunks)
  • tests/response.rs (5 hunks)

Summary by CodeRabbit

  • New Features

    • Introduced helper macros for testing, push_expect! and recv_expect!, providing clearer error messages and reducing boilerplate in asynchronous test code.
  • Documentation

    • Added a new section detailing the usage and benefits of the new helper macros, including example snippets.
  • Bug Fixes

    • Improved error reporting in tests by replacing .unwrap() calls with .expect() and the new macros, resulting in more informative failure messages.
  • Style

    • Reformatted several functions and control flows for improved readability without changing behaviour.

Walkthrough

Replace all .unwrap() calls with .expect() carrying explicit error messages throughout tests and some internal helpers, improving error diagnostics. Introduce and document two new macros, push_expect! and recv_expect!, for streamlined asynchronous test assertions. Apply minor formatting changes and clarify error handling in several internal functions without altering public APIs or core control flow.

Changes

Cohort / File(s) Change Summary
Test Error Handling Standardisation
tests/*, src/frame/tests.rs, src/server.rs, src/push.rs, src/connection.rs
Replace .unwrap() with .expect() and explicit messages in all test and helper code. Reformat some functions and control flow to multi-line blocks. Remove dead code warning in server test helper.
Testing Macros Introduction and Documentation
wireframe_testing/src/helpers.rs, docs/wireframe-testing-crate.md, tests/push.rs, tests/connection_actor.rs
Add and export push_expect! and recv_expect! macros for async test assertions. Update documentation to describe these macros. Refactor tests to use the macros instead of direct .unwrap() calls.
Internal Function Formatting
src/connection.rs, src/push.rs, src/server.rs
Reformat single-line function bodies to multi-line with braces. Adjust error handling in some private methods. No changes to public APIs.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Function
    participant Macro as push_expect!/recv_expect!
    participant Future as Async Operation

    Test->>Macro: push_expect!(future)
    Macro->>Future: await
    Future-->>Macro: Result (Ok or Err)
    alt Ok
        Macro-->>Test: Continue
    else Err
        Macro-->>Test: Panic with error message (file:line)
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

Replace the unwraps, let errors be clear,
With expect and macros, the intent is sincere.
Push and receive, now easier to test,
With line-numbered panics, debugging’s less stressed.
Code stands more robust, with clarity in sight,
🦀 Rustaceans rejoice—your tests are more right!

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/replace-.unwrap-with-.expect

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

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 31, 2025

🧙 Sourcery has finished reviewing your pull request!


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
Copy Markdown
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:

  • There’s a lot of repeated expect("... failed") boilerplate in the tests—consider extracting a small helper or macro (e.g. push_expect / recv_expect) to reduce noise and improve readability.
  • Many of the expect("recv failed") messages are identical; adding more context (like queue type or test name) would make it easier to pinpoint which receive call actually failed.
  • A couple of expect calls made in non-test code (e.g. bounded_no_rate_limit) will panic in library code—consider whether these should return a Result or use a debug_assert! instead to avoid unexpected panics in production.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- There’s a lot of repeated expect("... failed") boilerplate in the tests—consider extracting a small helper or macro (e.g. `push_expect` / `recv_expect`) to reduce noise and improve readability.
- Many of the `expect("recv failed")` messages are identical; adding more context (like queue type or test name) would make it easier to pinpoint which receive call actually failed.
- A couple of `expect` calls made in non-test code (e.g. `bounded_no_rate_limit`) will panic in library code—consider whether these should return a `Result` or use a `debug_assert!` instead to avoid unexpected panics in production.

## Individual Comments

### Comment 1
<location> `src/push.rs:312` </location>
<code_context>
         low_capacity: usize,
     ) -> (Self, PushHandle<F>) {
-        Self::bounded_with_rate_dlq(high_capacity, low_capacity, None, None).unwrap()
+        Self::bounded_with_rate_dlq(high_capacity, low_capacity, None, None)
+            .expect("bounded_no_rate_limit should not fail")
     }

</code_context>

<issue_to_address>
The expect message assumes infallibility; consider documenting why failure is impossible.

Please add a comment explaining why Self::bounded_with_rate_dlq cannot fail with these arguments.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        Self::bounded_with_rate_dlq(high_capacity, low_capacity, None, None)
            .expect("bounded_no_rate_limit should not fail")
=======
        // bounded_with_rate_dlq cannot fail here because both high_capacity and low_capacity are valid,
        // and passing None for the rate limiter and DLQ disables those features, which is always supported.
        Self::bounded_with_rate_dlq(high_capacity, low_capacity, None, None)
            .expect("bounded_no_rate_limit should not fail")
>>>>>>> REPLACE

</suggested_fix>

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.

Comment thread src/push.rs Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 2, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 2, 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.

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

♻️ Duplicate comments (4)
tests/connection_actor.rs (4)

79-88: Duplicate of the earlier comment: harmonise wording (“high-priority”), and switch to push_expect!.


213-232: Duplicate of the first comment: adopt push_expect! and consistent hyphenation.


272-276: Duplicate of the first comment: unify wording and use push_expect!.


406-410: Duplicate of the first comment: unify wording and use push_expect!.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f2c2e56 and 19bb776.

📒 Files selected for processing (21)
  • docs/wireframe-testing-crate.md (1 hunks)
  • src/frame/tests.rs (2 hunks)
  • src/push.rs (1 hunks)
  • src/server.rs (10 hunks)
  • tests/app_data.rs (2 hunks)
  • tests/async_stream.rs (1 hunks)
  • tests/connection_actor.rs (14 hunks)
  • tests/extractor.rs (3 hunks)
  • tests/lifecycle.rs (4 hunks)
  • tests/metadata.rs (1 hunks)
  • tests/middleware.rs (1 hunks)
  • tests/middleware_order.rs (1 hunks)
  • tests/preamble.rs (6 hunks)
  • tests/push.rs (8 hunks)
  • tests/push_policies.rs (4 hunks)
  • tests/response.rs (5 hunks)
  • tests/routes.rs (4 hunks)
  • tests/server.rs (2 hunks)
  • tests/session_registry.rs (1 hunks)
  • tests/wireframe_protocol.rs (3 hunks)
  • wireframe_testing/src/helpers.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • tests/routes.rs
  • tests/app_data.rs
  • tests/server.rs
  • tests/middleware.rs
  • wireframe_testing/src/helpers.rs
  • tests/metadata.rs
  • tests/async_stream.rs
  • tests/push_policies.rs
  • tests/response.rs
  • tests/middleware_order.rs
  • tests/lifecycle.rs
  • src/frame/tests.rs
  • src/push.rs
  • tests/extractor.rs
  • tests/wireframe_protocol.rs
  • tests/preamble.rs
  • tests/session_registry.rs
  • tests/connection_actor.rs
  • tests/push.rs
  • src/server.rs
**/*.md

⚙️ CodeRabbit Configuration File

**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")

  • Use en-GB-oxendict (-ize / -our) spelling and grammar
  • Paragraphs and bullets must be wrapped to 80 columns, except where a long URL would prevent this (in which case, silence MD013 for that line)
  • Code blocks should be wrapped to 120 columns.
  • Headings must not be wrapped.
  • Documents must start with a level 1 heading
  • Headings must correctly increase or decrease by no more than one level at a time
  • Use GitHub-flavoured Markdown style for footnotes and endnotes.
  • Numbered footnotes must be numbered by order of appearance in the document.

Files:

  • docs/wireframe-testing-crate.md
🧬 Code Graph Analysis (6)
tests/routes.rs (2)
src/message.rs (1)
  • from_bytes (50-55)
src/app.rs (6)
  • new_with_envelope (270-270)
  • default (234-247)
  • new (201-201)
  • new (257-257)
  • id (179-179)
  • id (209-209)
tests/app_data.rs (2)
src/extractor.rs (4)
  • from_message_request (184-187)
  • from_message_request (265-271)
  • from_message_request (328-335)
  • from_message_request (372-379)
tests/extractor.rs (2)
  • request (18-18)
  • empty_payload (25-25)
tests/push_policies.rs (1)
src/push.rs (2)
  • bounded_with_rate_dlq (384-418)
  • recv (438-444)
src/frame/tests.rs (1)
src/frame/conversion.rs (2)
  • bytes_to_u64 (49-68)
  • u64_to_bytes (78-114)
tests/wireframe_protocol.rs (4)
src/connection.rs (3)
  • new (30-34)
  • new (139-152)
  • new (511-520)
src/app.rs (3)
  • new (201-201)
  • new (257-257)
  • protocol (424-428)
tests/connection_actor.rs (1)
  • queues (24-24)
src/push.rs (1)
  • bounded (288-291)
tests/session_registry.rs (1)
tests/connection_actor.rs (1)
  • queues (24-24)
🔇 Additional comments (54)
src/push.rs (1)

312-318: Excellent improvement addressing past feedback.

The implementation now includes comprehensive documentation explaining why bounded_with_rate_dlq cannot fail when rate limiting is disabled, plus a debug assertion as a regression guard. This addresses the previous review concern about documenting infallibility assumptions.

wireframe_testing/src/helpers.rs (2)

282-282: LGTM - Clear error message.

The replacement provides a descriptive panic message that clearly indicates the failure source.


304-334: Excellent macro design for standardised test assertions.

The push_expect! and recv_expect! macros provide consistent error handling with call site information. The dual variants (with/without custom messages) offer flexibility whilst maintaining good diagnostics.

tests/middleware.rs (1)

58-58: LGTM - Descriptive error message.

The replacement improves test diagnostics by clearly indicating middleware call failures.

tests/middleware_order.rs (3)

57-63: Excellent error message specificity.

Each expect() call provides precise context about which operation failed, greatly improving test debugging capabilities.


69-75: Clear I/O operation error handling.

The error messages accurately describe the specific I/O operations that could fail during the test.


80-91: Comprehensive error coverage for async operations.

All async operations now have descriptive error messages, making test failures much easier to diagnose.

tests/async_stream.rs (1)

32-32: LGTM - Clear actor operation context.

The replacement provides specific context about the actor run failure, improving test diagnostics.

tests/metadata.rs (1)

22-22: Excellent error message improvements!

The replacement of .unwrap() with .expect() provides clear failure context. The messages "failed to create app" and "route registration failed" are descriptive and will aid debugging.

Also applies to: 26-26

tests/response.rs (1)

43-43: Systematic improvement to error diagnostics!

The comprehensive replacement of .unwrap() with .expect() throughout the file provides excellent error context. Each message is specific to the operation (e.g., "send_response failed", "decode failed", "deserialize failed"), which will significantly aid debugging test failures.

Also applies to: 48-50, 54-58, 70-70, 82-82, 123-123, 125-128, 135-135, 193-193

tests/routes.rs (1)

44-44: Thorough enhancement to test error reporting!

The systematic replacement of .unwrap() with .expect() provides clear, operation-specific error messages throughout the test functions. Messages like "encode failed", "decode failed", and "deserialize failed" will make test failures much easier to diagnose.

Also applies to: 56-57, 70-75, 83-83, 89-89, 93-93, 98-100, 104-104, 116-117, 120-121, 124-125, 128-129

tests/lifecycle.rs (1)

53-53: Consistent error handling improvements!

The replacement of .unwrap() with .expect() throughout the lifecycle tests provides clear failure context. Messages like "setup callback", "teardown callback", and "route registration failed" are descriptive and will facilitate debugging.

Also applies to: 55-55, 57-57, 78-78, 80-80, 93-93, 95-95, 124-124, 130-132, 136-136, 138-140

docs/wireframe-testing-crate.md (1)

120-130: Clear documentation of new helper macros!

The new "Helper macros" section effectively documents the push_expect! and recv_expect! macros. The explanation of their purpose and the usage examples are clear and helpful for users wanting to standardise error handling in asynchronous test code.

tests/session_registry.rs (1)

34-35: LGTM! Error messages improve test diagnostics.

The replacement of .unwrap() with .expect() calls providing clear context ("push failed", "recv failed") aligns with the coding guidelines and enhances debugging when these async operations fail.

tests/app_data.rs (2)

34-35: LGTM! Clear error message for state extraction.

The descriptive error message "failed to extract shared state" provides valuable context for debugging test failures during shared state extraction operations.


45-46: LGTM! Appropriate error message for error path testing.

The error message "missing state error expected" clearly indicates this is testing an expected error condition, improving test clarity and debugging.

tests/push_policies.rs (9)

43-49: LGTM! Consistent error messaging for push operations.

The descriptive error messages "push high priority failed" and "try_push failed" provide clear context for debugging async push operation failures.


51-51: LGTM! Clear error message for recv operation.

The error message "recv failed" provides appropriate context for debugging queue receive operation failures.


79-80: LGTM! Descriptive error message for queue creation.

The error message "queue creation failed" clearly identifies the failure point during queue setup operations.


82-88: LGTM! Consistent error messaging for async operations.

The error messages maintain consistency across push operations, improving test diagnostics without altering functionality.


90-92: LGTM! Clear error messages for recv operations.

The descriptive error messages "recv failed" and "dlq recv failed" provide specific context for debugging different receive operation failures.


98-98: LGTM! Appropriate error message for send operation.

The error message "send failed" provides clear context for debugging channel send operation failures.


108-108: LGTM! Consistent error messaging for DLQ operations.

The error message "dlq recv failed" maintains consistency with other receive operation error messages.


138-147: LGTM! Systematic error handling improvements.

The consistent application of descriptive error messages across queue creation and push operations enhances test diagnostics throughout the error scenario tests.


149-149: LGTM! Final recv operation properly handled.

The error message "recv failed" completes the systematic improvement of error handling across all async operations in this test file.

tests/extractor.rs (4)

38-38: LGTM! Clear error message for serialisation failure.

The error message "failed to serialise message" provides appropriate context for debugging message serialisation operations.


41-42: LGTM! Descriptive error message for extraction failure.

The error message "failed to extract TestMsg from payload" clearly identifies both the operation and the specific type being extracted, improving test diagnostics.


55-56: LGTM! Appropriate error message for connection info extraction.

The error message "failed to build ConnectionInfo" provides clear context for debugging connection information extraction failures.


70-71: LGTM! Consistent error messaging for shared state extraction.

The error message "failed to extract shared state" maintains consistency with similar operations across test files while providing clear debugging context.

src/frame/tests.rs (2)

23-26: LGTM! Clear error message for conversion operation.

The error message "failed to convert" provides appropriate context for debugging failures in the bytes_to_u64 conversion function during parameterised testing.


44-44: LGTM! Descriptive error message for encoding operation.

The error message "failed to encode u64" clearly identifies the specific encoding operation that failed, improving test diagnostics for the u64_to_bytes function.

tests/preamble.rs (1)

71-73: LGTM! Excellent error message improvements.

The replacement of .unwrap() with .expect() calls provides clear, contextual error messages that will significantly improve debugging when failures occur. All messages are descriptive and specific to their failure contexts.

Also applies to: 82-82, 87-87, 94-95, 100-100, 110-111, 145-145, 155-155, 163-165, 205-206, 214-214, 216-216, 218-218

tests/push.rs (3)

8-8: Good addition of helper macros.

Import of push_expect! and recv_expect! macros improves test consistency and error handling standardisation.


15-16: Excellent use of helper macros for async operations.

The consistent use of push_expect! and recv_expect! macros throughout the tests improves readability and provides better error context for async operations compared to direct .await.unwrap() calls.

Also applies to: 18-19, 35-35, 41-42, 73-74, 90-91, 94-95, 105-105, 107-107, 109-110, 122-122, 128-128, 130-131, 143-143, 147-148, 161-161, 171-171, 174-174


69-70: Clear queue creation error messages.

The .expect("queue creation failed") messages provide appropriate context for queue creation failures and follow the established pattern of descriptive error messages.

Also applies to: 103-104, 120-121, 157-158

tests/server.rs (1)

45-50: LGTM! Clear and descriptive error messages.

The .expect() calls provide excellent context for potential failures in socket operations and server execution. The messages are specific and will aid in debugging test failures.

Also applies to: 52-52, 62-62

tests/wireframe_protocol.rs (2)

54-56: Good error messages for app creation.

The .expect("failed to create app") calls provide clear context for WireframeApp::new() failures and improve debugging capabilities.

Also applies to: 78-80


84-87: Clear async operation error handling.

The .expect() calls for push operations and actor execution provide specific, actionable error messages that will aid in test failure diagnosis.

Also applies to: 97-97

src/server.rs (4)

534-538: Excellent test fixture error handling.

The .expect() calls in test fixtures provide clear, specific error messages for socket operations that will greatly improve debugging of test failures.

Also applies to: 614-616, 648-651


770-770: Clear server execution error messages.

The .expect() calls for server run operations provide appropriate context for timeout and execution failures in tests.

Also applies to: 797-797, 832-832


873-877: Good listener and address operation error handling.

The descriptive .expect() messages for TCP listener operations and address retrieval provide excellent debugging context for test failures.

Also applies to: 918-922, 926-926, 929-929


960-960: Comprehensive connection test error handling.

The .expect() calls throughout the connection panic test provide thorough error context for setup callbacks, socket operations, and server execution, improving test maintainability.

Also applies to: 964-972, 988-994, 1001-1001

tests/connection_actor.rs (12)

61-61: Run-path .expect() message is clear

The added context "actor run failed" is explicit enough for debugging.


93-93: No issues spotted

Message reads well and follows the same pattern as Line 61.


235-240: Message clarity OK

"value 42 should be present" succinctly explains the invariant; no action required.


260-260: Run-path .expect() message is sufficient

No further feedback.


282-282: Run-path .expect() message remains consistent

Looks good.


322-322: Run-path .expect() message remains consistent

No issues.


340-340: Run-path .expect() message remains consistent

No issues.


397-397: Run-path .expect() message remains consistent

No issues.


454-455: Run-path .expect() message remains consistent

No issues.


485-486: Run-path .expect() message remains consistent

No issues.


534-535: Run-path .expect() message remains consistent

No issues.


555-556: Run-path .expect() message remains consistent

No issues.

Comment thread tests/connection_actor.rs Outdated
Copy link
Copy Markdown

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
push.rs 9.69 → 10.00 Complex Conditional

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 added 3 commits August 3, 2025 14:16
Replace verbose await/expect pairs with the push_expect! helper to
standardise low- and high-priority push failure messages. Rewriting
let-chain expressions to nested conditionals keeps the build on stable
Rust, and lint expectations were relaxed accordingly.
@leynos leynos force-pushed the codex/replace-.unwrap-with-.expect branch from ac27ef4 to 23a2bbe Compare August 3, 2025 13:18
Copy link
Copy Markdown

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
push.rs 9.69 → 10.00 Complex Conditional

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

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
push.rs 9.69 → 10.00 Complex Conditional

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
Copy Markdown
Owner Author

leynos commented Aug 3, 2025

@coderabbitai new GitHub issue please:

ConnectionActor::process_high and process_low contain almost identical logic, indicating duplicate code that could be extracted into a helper.

Copy link
Copy Markdown
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: 11

♻️ Duplicate comments (2)
tests/connection_actor.rs (1)

55-56: LGTM: Consistent use of push_expect! macro with descriptive messages

The replacement of direct .await.unwrap() calls with push_expect! macros providing contextual error messages ("push high-priority", "push low-priority") follows the established pattern and addresses the previous review feedback about standardising failure messages.

Also applies to: 80-80, 82-82, 114-117, 122-125

src/push.rs (1)

316-321: LGTM: Excellent error handling with clear documentation

The explicit handling of bounded_with_rate_dlq result with explanatory comment, debug assertion, and descriptive expect message addresses the previous review feedback perfectly. This documents why failure is impossible whilst providing guard against future regressions.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ac27ef4 and 23a2bbe.

📒 Files selected for processing (22)
  • docs/wireframe-testing-crate.md (1 hunks)
  • src/connection.rs (4 hunks)
  • src/frame/tests.rs (2 hunks)
  • src/push.rs (4 hunks)
  • src/server.rs (11 hunks)
  • tests/app_data.rs (2 hunks)
  • tests/async_stream.rs (1 hunks)
  • tests/connection_actor.rs (16 hunks)
  • tests/extractor.rs (3 hunks)
  • tests/lifecycle.rs (4 hunks)
  • tests/metadata.rs (1 hunks)
  • tests/middleware.rs (1 hunks)
  • tests/middleware_order.rs (1 hunks)
  • tests/preamble.rs (6 hunks)
  • tests/push.rs (8 hunks)
  • tests/push_policies.rs (4 hunks)
  • tests/response.rs (5 hunks)
  • tests/routes.rs (4 hunks)
  • tests/server.rs (2 hunks)
  • tests/session_registry.rs (1 hunks)
  • tests/wireframe_protocol.rs (3 hunks)
  • wireframe_testing/src/helpers.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.rs

📄 CodeRabbit Inference Engine (AGENTS.md)

**/*.rs: Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider using Arc to reduce the amount of data returned.
Every module must begin with a module level (//!) comment explaining the module's purpose and utility.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Prefer immutable data and avoid unnecessary mut bindings.
Handle errors with the Result type instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Lints must not be silenced except as a last resort.
Lint rule suppressions must be tightly scoped and include a clear reason.
Prefer expect over allow.
Prefer .expect() over .unwrap().
Use concat!() to combine long string literals rather than escaping newlines with a backslash.
Prefer semantic error enums: Derive std::error::Error (via the thiserror crate) for any condition the caller might inspect, retry, or map to an HTTP status.
Use an opaque error only at the app boundary: Use eyre::Report for human-readable logs; these should not be exposed in public APIs.
Never export the opaque type from a library: Convert to domain enums at API boundaries, and to eyre only in the main main() entrypoint or top-level async task.

Files:

  • tests/async_stream.rs
  • tests/middleware.rs
  • tests/lifecycle.rs
  • tests/session_registry.rs
  • tests/metadata.rs
  • tests/app_data.rs
  • tests/preamble.rs
  • tests/middleware_order.rs
  • tests/response.rs
  • src/frame/tests.rs
  • tests/extractor.rs
  • tests/push.rs
  • tests/wireframe_protocol.rs
  • tests/push_policies.rs
  • src/connection.rs
  • src/push.rs
  • tests/connection_actor.rs
  • wireframe_testing/src/helpers.rs
  • tests/routes.rs
  • src/server.rs
  • tests/server.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • tests/async_stream.rs
  • tests/middleware.rs
  • tests/lifecycle.rs
  • tests/session_registry.rs
  • tests/metadata.rs
  • tests/app_data.rs
  • tests/preamble.rs
  • tests/middleware_order.rs
  • tests/response.rs
  • src/frame/tests.rs
  • tests/extractor.rs
  • tests/push.rs
  • tests/wireframe_protocol.rs
  • tests/push_policies.rs
  • src/connection.rs
  • src/push.rs
  • tests/connection_actor.rs
  • wireframe_testing/src/helpers.rs
  • tests/routes.rs
  • src/server.rs
  • tests/server.rs
docs/**/*.md

📄 CodeRabbit Inference Engine (AGENTS.md)

docs/**/*.md: Use the markdown files within the docs/ directory as a knowledge base and source of truth for project requirements, dependency choices, and architectural decisions.
When new decisions are made, requirements change, libraries are added/removed, or architectural patterns evolve, proactively update the relevant file(s) in the docs/ directory to reflect the latest state.

Conventions for writing project documentation as described in the documentation style guide

docs/**/*.md: Use British English based on the Oxford English Dictionary (en-oxendict) for documentation text.
The word "outwith" is acceptable in documentation.
Keep US spelling when used in an API, for example color.
Use the Oxford comma in documentation text.
Treat company names as collective nouns in documentation (e.g., "Lille Industries are expanding").
Write headings in sentence case in documentation.
Use Markdown headings (#, ##, ###, etc.) in order without skipping levels.
Follow markdownlint recommendations for Markdown files.
Provide code blocks and lists using standard Markdown syntax.
Always provide a language identifier for fenced code blocks; use plaintext for non-code text.
Use - as the first level bullet and renumber lists when items change.
Prefer inline links using [text](url) or angle brackets around the URL; avoid reference-style links like [foo][bar].
Ensure blank lines before and after bulleted lists and fenced blocks in Markdown.
Ensure tables have a delimiter line below the header row in Markdown.
Expand any uncommon acronym on first use, for example, Continuous Integration (CI).
Wrap paragraphs at 80 columns in documentation.
Wrap code at 120 columns in documentation.
Do not wrap tables in documentation.
Use sequentially numbered footnotes referenced with [^1] and place definitions at the end of the file.
Where it adds clarity, include Mermaid diagrams in documentation.
When embedding figures, use ![alt text](path/to/image) and provide concise ...

Files:

  • docs/wireframe-testing-crate.md
**/*.md

📄 CodeRabbit Inference Engine (AGENTS.md)

**/*.md: Documentation must use en-GB-oxendict spelling and grammar, except for the naming of the "LICENSE" file.
Validate Markdown files using make markdownlint.
Run make fmt after any documentation changes to format all Markdown files and fix table markup.
Validate Mermaid diagrams in Markdown files by running make nixie.
Markdown paragraphs and bullet points must be wrapped at 80 columns.
Code blocks in Markdown must be wrapped at 120 columns.
Tables and headings in Markdown must not be wrapped.
Use dashes (-) for list bullets in Markdown.
Use GitHub-flavoured Markdown footnotes ([^1]) for references and footnotes.

Files:

  • docs/wireframe-testing-crate.md

⚙️ CodeRabbit Configuration File

**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")

  • Use en-GB-oxendict (-ize / -our) spelling and grammar
  • Paragraphs and bullets must be wrapped to 80 columns, except where a long URL would prevent this (in which case, silence MD013 for that line)
  • Code blocks should be wrapped to 120 columns.
  • Headings must not be wrapped.
  • Documents must start with a level 1 heading
  • Headings must correctly increase or decrease by no more than one level at a time
  • Use GitHub-flavoured Markdown style for footnotes and endnotes.
  • Numbered footnotes must be numbered by order of appearance in the document.

Files:

  • docs/wireframe-testing-crate.md
docs/**/*.{md,rs}

📄 CodeRabbit Inference Engine (docs/multi-packet-and-streaming-responses-design.md)

docs/**/*.{md,rs}: The official documentation and examples must exclusively use the declarative Response model for handler responses.
The async-stream pattern must be documented as the canonical approach for dynamic stream generation.

Files:

  • docs/wireframe-testing-crate.md
🧬 Code Graph Analysis (9)
tests/lifecycle.rs (3)
tests/routes.rs (3)
  • BincodeSerializer (72-73)
  • BincodeSerializer (118-119)
  • BincodeSerializer (126-127)
src/app.rs (3)
  • new (201-201)
  • new (257-257)
  • default (234-247)
wireframe_testing/src/helpers.rs (1)
  • run_app_with_frame (342-352)
tests/session_registry.rs (1)
tests/connection_actor.rs (1)
  • queues (25-27)
tests/metadata.rs (2)
src/app.rs (5)
  • default (234-247)
  • serializer (453-469)
  • serializer (513-513)
  • new (201-201)
  • new (257-257)
src/server.rs (1)
  • new (96-112)
tests/app_data.rs (2)
src/extractor.rs (4)
  • from_message_request (184-187)
  • from_message_request (265-271)
  • from_message_request (328-335)
  • from_message_request (372-379)
tests/extractor.rs (2)
  • request (18-18)
  • empty_payload (25-25)
tests/response.rs (3)
src/app.rs (4)
  • default (234-247)
  • new (201-201)
  • new (257-257)
  • from (143-143)
wireframe_testing/src/helpers.rs (1)
  • processor (22-22)
src/message.rs (1)
  • from_bytes (50-55)
tests/extractor.rs (2)
src/extractor.rs (4)
  • from_message_request (184-187)
  • from_message_request (265-271)
  • from_message_request (328-335)
  • from_message_request (372-379)
tests/app_data.rs (2)
  • request (19-19)
  • empty_payload (26-26)
tests/push.rs (2)
tests/connection_actor.rs (1)
  • queues (25-27)
src/push.rs (5)
  • bounded (292-295)
  • push_low_priority (169-171)
  • push_high_priority (143-145)
  • recv (442-448)
  • bounded_with_rate (348-354)
src/connection.rs (1)
tests/connection_actor.rs (1)
  • shutdown_token (34-36)
tests/routes.rs (2)
src/message.rs (1)
  • from_bytes (50-55)
src/app.rs (6)
  • new_with_envelope (270-270)
  • default (234-247)
  • new (201-201)
  • new (257-257)
  • id (179-179)
  • id (209-209)
🪛 GitHub Check: build-test
src/connection.rs

[warning] 196-196:
Diff in /home/runner/work/wireframe/wireframe/src/connection.rs


[warning] 459-459:
Diff in /home/runner/work/wireframe/wireframe/src/connection.rs

tests/connection_actor.rs

[warning] 22-22:
Diff in /home/runner/work/wireframe/wireframe/tests/connection_actor.rs

🪛 GitHub Actions: CI
src/connection.rs

[warning] 40-40: Prettier-like formatting warning: function active_connection_count should be formatted in a single line.


[warning] 187-187: Prettier-like formatting warning: function set_response should be formatted in a single line.


[warning] 196-196: Prettier-like formatting warning: function shutdown_token should be formatted in a single line.


[warning] 450-450: Prettier-like formatting warning: async function wait_shutdown should be formatted in a single line.


[warning] 459-459: Prettier-like formatting warning: async function recv_push should be formatted in a single line.


[warning] 541-541: Prettier-like formatting warning: function is_active should be formatted in a single line.


[warning] 541-541: Prettier-like formatting warning: function is_shutting_down should be formatted in a single line.


[warning] 541-541: Prettier-like formatting warning: function is_done should be formatted in a single line.

src/push.rs

[warning] 97-97: Prettier-like formatting warning: function from_arc should be formatted in a single line.


[warning] 255-255: Prettier-like formatting warning: function downgrade should be formatted in a single line.

tests/connection_actor.rs

[warning] 22-22: Prettier-like formatting warning: function queues should be formatted in a single line.


[warning] 31-31: Prettier-like formatting warning: function shutdown_token should be formatted in a single line.


[warning] 40-40: Prettier-like formatting warning: function empty_stream should be formatted in a single line.

src/server.rs

[warning] 229-229: Prettier-like formatting warning: function worker_count should be formatted in a single line.

🔇 Additional comments (63)
wireframe_testing/src/helpers.rs (2)

457-457: LGTM: Clear error context added.

The replacement of .unwrap() with .expect("server task panicked") provides explicit context for task failures, aligning perfectly with the PR objectives.


490-520: Well-designed test helper macros.

The push_expect! and recv_expect! macros provide excellent standardisation for asynchronous test error handling. The inclusion of file and line information will significantly improve debugging efficiency.

Key strengths:

  • Clear documentation with debug build context
  • Two variants allowing custom messages
  • Proper macro export for test usage
  • Consistent error message formatting
tests/async_stream.rs (1)

32-32: LGTM: Improved error context for actor failures.

The replacement provides clear context when the actor run fails, enhancing test failure diagnostics.

tests/middleware.rs (1)

58-58: LGTM: Clear middleware failure context.

The descriptive error message will help identify middleware call failures more effectively during testing.

tests/metadata.rs (1)

22-22: LGTM: Enhanced error context for app setup.

Both changes provide clear, specific error messages for common test setup failures:

  • App creation failure context at line 22
  • Route registration failure context at line 26

These improvements will significantly aid debugging when test setup fails.

Also applies to: 26-26

tests/session_registry.rs (1)

34-35: LGTM: Clear async operation error context.

Both changes provide descriptive error messages for push and receive operations, improving test failure diagnostics. The explicit .expect() calls are appropriate and consistent with the PR objectives.

tests/lifecycle.rs (6)

52-58: Excellent error message improvements.

The replacement of .unwrap() with descriptive .expect() messages enhances test failure diagnostics whilst maintaining the same control flow.


77-80: LGTM! Consistent error handling improvement.

The expect messages align well with the previous function and provide clear failure context.


92-95: Consistent error handling enhancement.

The expect messages maintain consistency across the test suite and provide clear diagnostic information.


124-124: Good error message for route registration.

The descriptive expect message clearly identifies the failing operation.


130-132: Proper British spelling in error message.

The expect message correctly uses "serialise" following the en-GB spelling requirements in the coding guidelines.


134-141: Clear error messages for encoding and execution.

The expect messages provide good diagnostic context for frame encoding and application execution failures.

tests/response.rs (8)

42-43: Consistent app creation error handling.

The expect message aligns with the pattern used throughout the test suite.


48-50: Clear error message for response sending.

The expect message provides good context for send_response failures.


54-58: Comprehensive error handling for decoding pipeline.

The expect messages clearly identify each step in the decode-decode-deserialize chain, improving failure diagnostics.


70-70: Consistent decode error handling.

The expect message maintains consistency with other decoding operations.


82-82: Consistent decode error handling.

The expect message maintains consistency across decode operations.


123-123: Clear encoding error message.

The expect message provides good context for encoding failures.


125-128: Consistent decode error handling.

The expect messages provide clear context for both decode operations and frame presence checks.


193-193: Correct app creation error message.

The expect message properly identifies the app creation operation.

src/frame/tests.rs (2)

27-30: Clear conversion error message.

The expect message provides good context for bytes-to-u64 conversion failures in test assertions.


48-48: Descriptive encoding error message.

The expect message clearly identifies the u64 encoding operation that failed.

docs/wireframe-testing-crate.md (1)

123-133: Excellent documentation for helper macros.

The new section clearly explains the purpose and usage of the push_expect! and recv_expect! macros, with practical examples that demonstrate their value in reducing test boilerplate.

tests/routes.rs (11)

43-44: Consistent app creation error handling.

The expect message maintains consistency with the pattern used throughout the test suite.


55-56: Clear route registration error message.

The expect message properly identifies the route registration operation.


57-57: Appropriate encoding error message.

The expect message provides clear context for message encoding failures.


70-71: Clear frame decoding error messages.

The expect messages provide good diagnostic context for both decode operations and frame presence checks.


72-74: Consistent deserialization error handling.

The expect message clearly identifies the deserialization operation.


75-75: Contextually appropriate error message.

The expect message specifically mentions "echo" which provides good context for this test case.


82-83: Consistent app creation error handling.

The expect message maintains consistency across app creation operations.


88-89: Consistent route registration error handling.

The expect message maintains consistency with other route registration operations.


93-93: Consistent encoding error handling.

The expect message maintains consistency with other encoding operations.


104-104: Consistent encoding error handling.

The expect message maintains consistency with other encoding operations.


116-129: Comprehensive and consistent error handling.

All expect messages maintain consistency with the established patterns and provide clear diagnostic context for the decode-deserialize pipeline operations.

tests/app_data.rs (2)

34-35: LGTM - Clear error message for state extraction.

The .expect() call provides a descriptive error message that will aid debugging if the extraction fails.


46-46: LGTM - Appropriate error message for test expectation.

The error message clearly indicates this is an expected error condition in the test context.

tests/middleware_order.rs (3)

56-63: LGTM - Clear error messages for app setup.

The .expect() calls provide descriptive error messages for app creation, route registration, and middleware wrapping operations.


69-75: LGTM - Descriptive error messages for I/O operations.

The error messages clearly identify which serialization, encoding, or I/O operation failed, improving test debugging.


84-90: LGTM - Clear error context for frame processing.

The chained .expect() calls provide specific error messages for each step of frame decoding and deserialization.

tests/extractor.rs (3)

38-38: LGTM - Proper error message with British spelling.

The .expect() call uses "serialise" (British spelling) which aligns with the coding guidelines requiring en-GB spelling.


41-42: LGTM - Type-specific error message.

The error message clearly identifies the specific type (TestMsg) being extracted, improving debugging context.


55-56: LGTM - Consistent error messaging pattern.

Both ConnectionInfo and SharedState extraction use descriptive error messages that clearly identify the failed operation.

Also applies to: 70-71

tests/push_policies.rs (3)

43-49: LGTM - Clear push operation error messages.

The error messages distinguish between different push operations ("push high priority failed" vs "try_push failed"), providing specific debugging context.


79-80: LGTM - Consistent queue creation error handling.

The "queue creation failed" message is used consistently across different test scenarios, improving debugging clarity.

Also applies to: 138-139


92-92: LGTM - DLQ-specific error messages.

The error messages are specific to Dead Letter Queue operations ("dlq recv failed"), making test failures easier to diagnose.

Also applies to: 108-108

tests/preamble.rs (3)

71-73: LGTM - Clear server operation error messages.

The error messages provide specific context for server setup and lifecycle operations ("bind", "server run failed", "server join failed").

Also applies to: 82-82, 87-87


94-95: LGTM - Consistent I/O operation error messages.

The I/O error messages follow a consistent pattern ("write failed", "read failed", "shutdown failed") that will aid in debugging network operations.

Also applies to: 110-111, 164-165, 205-206, 216-216, 218-218


145-145: LGTM - Appropriate concurrency error message.

The "lock poisoned" message clearly indicates a concurrency issue, which is the standard terminology for this type of failure in Rust.

Also applies to: 155-155

tests/push.rs (3)

8-8: LGTM: Proper import of new testing macros

The import of push_expect! and recv_expect! macros aligns with the PR's objective to standardise error handling in tests.


15-16: LGTM: Consistent use of testing macros

The replacement of .await.unwrap() with push_expect! and recv_expect! macros provides better error diagnostics whilst maintaining the same test logic.

Also applies to: 18-19


69-70: LGTM: Descriptive error messages for queue creation

The .expect("queue creation failed") calls provide clear context when bounded_with_rate fails, which is appropriate for test scenarios.

Also applies to: 103-104, 120-121, 157-158

tests/wireframe_protocol.rs (2)

54-56: LGTM: Clear error messages for app creation

The .expect("failed to create app") provides clear context when WireframeApp::new() fails.

Also applies to: 78-80


84-87: LGTM: Descriptive error handling for async operations

The explicit .expect() calls with descriptive messages ("push failed", "actor run failed") improve error diagnostics over generic unwrap panics.

Also applies to: 97-97

tests/server.rs (1)

45-50: LGTM: Context-specific error messages for server operations

The replacement of .unwrap() with descriptive .expect() calls provides clear failure context for socket operations, binding, and server execution.

Also applies to: 52-52, 62-62

tests/connection_actor.rs (1)

62-62: LGTM: Descriptive error messages for actor operations

The .expect("actor run failed") calls provide clear context when ConnectionActor::run() fails, improving error diagnostics over generic unwrap panics.

Also applies to: 88-88, 182-182, 247-247, 266-266, 306-306, 324-324, 381-381, 432-432, 463-463, 512-512, 533-533

src/push.rs (1)

394-398: LGTM: Rate validation logic restructuring

The restructuring from combined if let with condition to nested structure maintains the same validation semantics whilst potentially improving readability.

src/server.rs (7)

577-581: LGTM!

Excellent replacement of .unwrap() with meaningful .expect() messages that clearly indicate the failure context for test setup.


657-659: LGTM!

Good use of .expect() with a descriptive message that clearly indicates what should be available after binding.


691-693: LGTM!

Clear and descriptive .expect() message that properly indicates the expected state after binding.


563-566: Clarify the attribute change rationale.

The change from #[expect(dead_code)] to #[allow(dead_code)] appears unrelated to the main PR objective of replacing .unwrap() with .expect(). While both are valid lint suppressions, this change should be explained.

Based on the coding guidelines preference for #[expect] over #[allow], was this change intentional? The guidelines state "Prefer expect over allow."


916-920: LGTM!

Excellent replacement of .unwrap() calls with meaningful .expect() messages throughout the test code. These provide clear context for debugging test failures.

Also applies to: 961-965, 969-969, 972-972


512-516: LGTM!

The restructuring from a combined if let with logical AND to nested if let statements improves readability without changing the logic. This aligns with the coding guidelines for clarity.


1052-1052: LGTM!

Comprehensive replacement of .unwrap() calls with descriptive .expect() messages throughout the test. These provide excellent debugging context for test failures.

Also applies to: 1056-1060, 1062-1064, 1073-1073, 1080-1086, 1093-1093

Comment thread src/connection.rs
Comment thread src/connection.rs Outdated
Comment thread src/connection.rs Outdated
Comment thread src/connection.rs Outdated
Comment thread src/connection.rs Outdated
Comment thread src/push.rs
Comment thread src/server.rs
Comment thread tests/connection_actor.rs Outdated
Comment thread tests/response.rs Outdated
Comment thread tests/routes.rs
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 3, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

I'll examine the ConnectionActor code first to understand the duplication, then create the GitHub issue for you.

Now I'll create the GitHub issue:

@leynos I've created a GitHub issue to track the duplicate code in ConnectionActor::process_high and process_low methods. The issue includes the context you provided and links back to this PR and comment for reference.


🏁 Script executed:

#!/bin/bash
# Search for ConnectionActor and its process_high and process_low methods
ast-grep --pattern $'impl $_ for ConnectionActor$_ {
  $$$
  fn process_high($$$) {
    $$$
  }
  $$$
  fn process_low($$$) {
    $$$
  }
  $$$
}'

Length of output: 147


🏁 Script executed:

#!/bin/bash
# Search for the ConnectionActor struct and its methods more broadly
rg "ConnectionActor" -A 20 -B 5

Length of output: 64058


🏁 Script executed:

#!/bin/bash
# Find files containing ConnectionActor
fd -t f -x grep -l "ConnectionActor" {}

Length of output: 306


🏁 Script executed:

#!/bin/bash
# Look for process_high and process_low methods specifically
rg "fn process_(high|low)" -A 15 -B 2

Length of output: 1671


🏁 Script executed:

#!/bin/bash
# Create GitHub issue for the duplicate code
gh issue create \
  --title "Extract duplicate logic from ConnectionActor::process_high and process_low into helper method" \
  --body "**Description**

The \`ConnectionActor::process_high\` and \`process_low\` methods contain almost identical logic, indicating duplicate code that could be extracted into a helper method for better maintainability.

**Context**

This duplication was identified during code review and represents an opportunity to reduce code repetition and improve maintainability.

**Backlinks**

- PR: https://github.com/leynos/wireframe/pull/225
- Comment: https://github.com/leynos/wireframe/pull/225#issuecomment-<comment_id>

**Requested by:** @leynos" \
  --assignee leynos

Length of output: 731


@leynos I've successfully created GitHub issue #251 to track the duplicate code in ConnectionActor::process_high and process_low methods.

Looking at the code, I can see the duplication you identified. Both methods follow an almost identical pattern:

  1. Check if a frame is received (if let Some(frame) = res)
  2. If yes: call process_frame_common(), then call priority-specific after method
  3. If no: call handle_closed_receiver() and potentially reset fairness

The main differences are:

  • process_high calls self.after_high(out, state) vs process_low calls self.after_low()
  • process_high calls self.fairness.reset() when the receiver is closed

This duplication could indeed be extracted into a helper method that takes the priority-specific callbacks as parameters.

The issue has been created with the appropriate title, description, and backlinks to this PR and comment for future reference.

🐰✨ ears perk up with organizational satisfaction

* Handle missing TryRecvError and fix test message

* Apply formatting
Copy link
Copy Markdown

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
push.rs 9.69 → 10.00 Complex Conditional

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

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
push.rs 9.69 → 10.00 Complex Conditional

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

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
push.rs 9.69 → 10.00 Complex Conditional

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

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
push.rs 9.69 → 10.00 Complex Conditional

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
Copy Markdown
Owner Author

leynos commented Aug 3, 2025

@coderabbitai Are Pong and EmptyPreamble actually used in the codebase? Should they just be removed?

    Checking wireframe_testing v0.1.0 (/home/runner/work/wireframe/wireframe/wireframe_testing)
error: struct `Pong` is never constructed
Error:   --> examples/metadata_routing.rs:64:8
   |
64 | struct Pong;
   |        ^^^^
   |
   = note: `-D dead-code` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(dead_code)]`

error: could not compile `wireframe` (example "metadata_routing") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: struct `EmptyPreamble` is never constructed
Error:    --> src/server.rs:567:12
    |
567 |     struct EmptyPreamble;
    |            ^^^^^^^^^^^^^
    |
    = note: `-D dead-code` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(dead_code)]`

error: could not compile `wireframe` (lib test) due to 1 previous error
Error: Process completed with exit code 101.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 3, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for all occurrences of Pong and EmptyPreamble in the codebase
echo "=== Searching for 'Pong' ==="
rg "Pong" -n -A 3 -B 3

echo -e "\n=== Searching for 'EmptyPreamble' ==="
rg "EmptyPreamble" -n -A 3 -B 3

echo -e "\n=== Looking at the specific files mentioned in the errors ==="
echo "--- examples/metadata_routing.rs around line 64 ---"
sed -n '60,70p' examples/metadata_routing.rs

echo -e "\n--- src/server.rs around line 567 ---"
sed -n '563,575p' src/server.rs

Length of output: 6968


🏁 Script executed:

#!/bin/bash
# Check if EmptyPreamble is used in any doctests or documentation
echo "=== Checking for EmptyPreamble usage in doctests ==="
rg "EmptyPreamble" -A 10 -B 10

echo -e "\n=== Looking for any doctests in server.rs that might reference it ==="
rg "```" src/server.rs -A 20 -B 5 | head -50

echo -e "\n=== Check if the metadata_routing.rs Pong is referenced anywhere ==="
cd examples && rg "Pong" metadata_routing.rs -A 5 -B 5

Length of output: 1309


🏁 Script executed:

#!/bin/bash
# Search for doctests in server.rs more carefully
echo "=== Looking for doctests in server.rs ==="
grep -n "///" src/server.rs | head -20

echo -e "\n=== Search for any actual usage of EmptyPreamble ==="
ast-grep --pattern 'EmptyPreamble'

echo -e "\n=== Check what's around EmptyPreamble definition ==="
sed -n '560,580p' src/server.rs

echo -e "\n=== Check if Pong in metadata_routing.rs is used anywhere in that file ==="
grep -n "Pong" examples/metadata_routing.rs

Length of output: 2325


@leynos Based on my analysis of the codebase, both Pong and EmptyPreamble are indeed dead code that should be removed:

Pong in examples/metadata_routing.rs:

  • Line 64 defines struct Pong; with a comment explicitly stating it's a "Placeholder for demonstration of metadata routing; not used directly"
  • It's never referenced anywhere else in that file
  • This is different from the Pong struct in examples/ping_pong.rs, which is actively used

EmptyPreamble in src/server.rs:

  • Line 567 defines struct EmptyPreamble; with a comment claiming it's "Used only in doctest to illustrate an empty preamble"
  • However, I found no doctests or any other code that actually uses this struct
  • It appears to be leftover code that was intended for documentation but never implemented

Recommendation:
Remove both structs entirely since they serve no purpose:

  1. Delete struct Pong; from examples/metadata_routing.rs:64
  2. Delete struct EmptyPreamble; and its comment from src/server.rs:567

This will eliminate the dead code warnings and clean up the codebase. If these were meant to serve as examples or placeholders, they're not fulfilling that purpose currently.

🐰🧹 tidying up with a satisfied hop

Copy link
Copy Markdown

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
push.rs 9.69 → 10.00 Complex Conditional

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

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
push.rs 9.69 → 10.00 Complex Conditional

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 leynos merged commit 03b951b into main Aug 3, 2025
5 checks passed
@leynos leynos deleted the codex/replace-.unwrap-with-.expect branch August 3, 2025 15:29
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