Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing cantdo reasons on cantdo msgs #407

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

grunch
Copy link
Member

@grunch grunch commented Dec 27, 2024

Bug fixes
bumps mostro core version

Summary by CodeRabbit

  • New Features

    • Enhanced error messaging across various actions by specifying reasons for failures related to public key validation and order status.
  • Bug Fixes

    • Improved clarity in error handling for user creation and order cancellations.
  • Documentation

    • Updated messaging to provide more informative feedback for users encountering issues.

Bug fixes
bumps mostro core version
Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Walkthrough

This pull request introduces a series of updates across multiple files in the Rust project, primarily focusing on enhancing error handling by incorporating the CantDoReason enum from the mostro_core::message module. The changes span various application modules like admin_add_solver, cancel, dispute, fiat_sent, order, take_buy, and take_sell. Each modification aims to provide more specific and informative error messages when certain conditions are not met, such as invalid public keys, order statuses, or parameters.

Changes

File Change Summary
Cargo.toml Updated mostro-core dependency version from 0.6.20 to 0.6.21
src/app/admin_add_solver.rs Added CantDoReason import, enhanced error handling with InvalidPubkey reason
src/app/admin_take_dispute.rs Added CantDoReason import, improved error messaging with InvalidPubkey
src/app/cancel.rs Added CantDoReason import, added checks for already canceled orders
src/app/dispute.rs Added CantDoReason import, enhanced public key error handling
src/app/fiat_sent.rs Added CantDoReason import, improved error messaging for invalid public keys
src/app/order.rs Updated imports, added specific error reasons for invalid amounts and parameters
src/app/rate_user.rs Enhanced error messaging for invalid order status
src/app/take_buy.rs Added CantDoReason import, improved error handling for order taking
src/app/take_sell.rs Enhanced error messaging for invalid public keys and invoices
src/util.rs Changed error reason from InvalidPeer to InvalidPubkey

Possibly related PRs

Poem

🐰 Hop, hop, through the code we go,
Errors now speak with reasons to know
Invalid keys and statuses clear
Our messages now bring insight near
A rabbit's guide to debugging's art! 🔍


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@grunch
Copy link
Member Author

grunch commented Dec 27, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

✅ 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
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: 0

🧹 Nitpick comments (3)
src/app/take_buy.rs (1)

41-47: Evaluate the InvalidPubkey reason for taking one’s own order.
Using CantDoReason::InvalidPubkey to handle the maker’s attempt to take their own order might be semantically imprecise. Consider introducing a more fitting variant (e.g., CantDoReason::OwnOrder) if you want clearer semantics in your code.

src/app/take_sell.rs (1)

42-48: Consider a more specific CantDoReason.
As with the take-buy flow, returning CantDoReason::InvalidPubkey for an attempt to take one’s own order may be misleading. A dedicated reason (e.g., CantDoReason::OwnOrder) could improve clarity.

src/util.rs (1)

640-640: Improve test coverage for the new error reason.

This is a good replacement of CantDoReason::InvalidPeer with CantDoReason::InvalidPubkey, which clarifies the condition being violated. As a follow-up, consider adding or expanding unit/integration tests to ensure that the code properly handles and reports this newly specified reason.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cf85572 and eceac66.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • Cargo.toml (1 hunks)
  • src/app.rs (1 hunks)
  • src/app/admin_add_solver.rs (2 hunks)
  • src/app/admin_take_dispute.rs (2 hunks)
  • src/app/cancel.rs (3 hunks)
  • src/app/dispute.rs (2 hunks)
  • src/app/fiat_sent.rs (2 hunks)
  • src/app/order.rs (3 hunks)
  • src/app/rate_user.rs (1 hunks)
  • src/app/take_buy.rs (2 hunks)
  • src/app/take_sell.rs (1 hunks)
  • src/util.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
🔇 Additional comments (17)
src/app/admin_add_solver.rs (2)

5-5: New import looks good.
The newly introduced CantDoReason import aligns well with the subsequent usage in send_cant_do_msg.


38-44: Consider verifying the optional parameters for send_cant_do_msg.
Currently, you're passing None for the order ID, and Some(CantDoReason::InvalidPubkey) for the reason. While this makes sense for an invalid key scenario, double-check if you want to include additional context (e.g., an order or trade index) to facilitate debugging or tracking the error downstream.

src/app/fiat_sent.rs (2)

4-4: Import usage verified.
The addition of CantDoReason is consistent with the approach for providing detailed error messaging.


49-55: Check reason alignment with business requirements.
The use of CantDoReason::InvalidPubkey accurately flags the discrepancy between the buyer’s actual pubkey and the one tied to the order. Ensure this is the intended reason for blocking the action.

src/app/take_buy.rs (1)

7-7: Import statement is coherent.
Adding CantDoReason matches your need to provide more descriptive error messaging.

src/app/admin_take_dispute.rs (2)

7-7: Good import for enhanced error reporting.
Importing CantDoReason here neatly paves the way for more descriptive error messages, boosting usability and debuggability.


77-83: Specific error reason adds clarity.
By specifying CantDoReason::InvalidPubkey instead of a more generic reason or None, the error handling becomes clearer and more informative for users. This is a beneficial step for improved maintainability and quick troubleshooting.

src/app/rate_user.rs (1)

83-89: Concise and informative error message.
Providing CantDoReason::InvalidOrderStatus gives a clear indication of why the rate operation fails. This direct mapping between status checks and error messages is helpful for both developers and end users.

src/app/dispute.rs (2)

14-14: Import aligns with overall improvements.
Including the CantDoReason import strongly complements the broader pattern of more descriptive error handling introduced throughout the codebase.


187-193: Specific invalid pubkey handling.
Using CantDoReason::InvalidPubkey precisely informs users and maintainers about the cause of the dispute initiation failure. This is a great improvement in clarity relative to more generic error feedback.

src/app.rs (1)

140-140: New reason clarifies user creation failures.
Replacing a less specific reason with CantDoReason::CantCreateUser is a good move toward transparent error reporting, as it accurately conveys the root cause of the failure scenario when creating new users.

src/app/order.rs (3)

5-5: Explicit import of CantDoReason.

Including CantDoReason in the import statement aligns it with other code sections that require detailed reasons for non-executable operations. This is consistent and clear.


52-58: Appropriate use of CantDoReason::InvalidAmount.

Sending a CantDoReason::InvalidAmount message when min >= max is a clearer error explanation, preventing confusion for the end user. This is a good improvement for error reporting logic.


81-88: Validate contradiction between premium and fiat_amount.

Rejecting orders that incorrectly specify both premium and a fiat_amount ensures the logic remains consistent. However, if you anticipate a scenario where both might coexist in the future, consider documenting that or revisiting the validation approach as requirements evolve.

src/app/cancel.rs (3)

9-9: Add CantDoReason to improve explanatory error messages.

Importing CantDoReason here creates consistent and informative error handling across the application.


43-55: Enhanced flow for already-canceled orders.

Proactively detecting when an order is already canceled and communicating that via send_cant_do_msg prevents confusing re-cancellation attempts. This is a neat improvement in user feedback.


92-92: Restrict cancellation condition to WaitingBuyerInvoice.

The added check ensures that the cancel_add_invoice routine is only executed under the correct status, mitigating edge cases. This approach further refines logic flow for sellers.

@grunch grunch merged commit 1aac442 into main Dec 27, 2024
2 checks passed
@grunch grunch deleted the handles-cancelled-order-cancel-request branch December 27, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant