Skip to content

Add more details to exception - #541

Merged
AngeloTadeucci merged 1 commit into
masterfrom
dev2
Jul 14, 2025
Merged

Add more details to exception#541
AngeloTadeucci merged 1 commit into
masterfrom
dev2

Conversation

@AngeloTadeucci

@AngeloTadeucci AngeloTadeucci commented Jul 13, 2025

Copy link
Copy Markdown
Collaborator

Log errors from field manager packet processing
Add pending state to channels

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling in inventory, housing, and mail management to prevent exceptions from propagating and provide clearer error messages.
    • Enhanced logging for packet processing to better capture and distinguish error types.
  • New Features

    • Introduced a new "Pending" status for channels, enabling more precise control over channel activation and monitoring.
  • Other Improvements

    • Adjusted timestamp initialization for nurturing records to use the current time.
    • Improved diagnostic information in inventory logs and exceptions.

Log errors from field manager packet processing
Add pending state to channels
@coderabbitai

coderabbitai Bot commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce refined error handling and logging across several server management classes, including adjustments to exception flows and log details. The channel management logic is updated to support a new Pending status, modifying channel selection and monitoring behavior. Additionally, the initialization of nurturing records now uses the current time for the last feed event.

Changes

File(s) Change Summary
Maple2.Database/Storage/Game/GameStorage.Nurturing.cs Sets LastFeedTime to DateTime.Now instead of DateTime.MinValue during nurturing creation.
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs Adds try-catch for packet processing; logs IndexOutOfRangeException and other exceptions differently.
Maple2.Server.Game/Manager/HousingManager.cs Changes TryRemoveCube to log errors and return false instead of throwing on cube retrieval failure.
Maple2.Server.Game/Manager/Items/InventoryManager.cs Enhances log and exception messages in ConsumeItemComponents to include both Uid and Id.
Maple2.Server.Game/Manager/MailManager.cs Introduces Serilog logging; replaces exception with error log and error code in CollectInternal.
Maple2.Server.World/Containers/ChannelClientLookup.cs Adds Pending to ChannelStatus; updates channel creation, lookup, and monitoring logic for new status.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ChannelClientLookup
    participant Channel

    Client->>ChannelClientLookup: FindOrCreateChannelByIp(ip, instancedContent)
    alt Channel with Inactive status exists
        ChannelClientLookup->>Channel: Set status to Pending
        ChannelClientLookup-->>Client: Return Pending channel
    else No suitable channel
        ChannelClientLookup->>Channel: Create new channel with Pending status
        ChannelClientLookup-->>Client: Return new Pending channel
    end

    Note over ChannelClientLookup,Channel: MonitorChannel may transition Pending <-> Active/Inactive
Loading

Possibly related PRs

  • Simplify channel lookup logic #388: Both PRs modify FindOrCreateChannelByIp in channel management, with this PR introducing a new Pending status and the related PR refactoring the lookup logic.

Suggested reviewers

  • Zintixx

Poem

In channels now a Pending state,
Logs grow wise, exceptions abate.
Nurturing starts with time anew,
Rabbits cheer for changes true!
With careful hops and gentle paws,
The code now follows softer laws.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e8f6bf1 and 4159e4b.

📒 Files selected for processing (6)
  • Maple2.Database/Storage/Game/GameStorage.Nurturing.cs (1 hunks)
  • Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (1 hunks)
  • Maple2.Server.Game/Manager/HousingManager.cs (1 hunks)
  • Maple2.Server.Game/Manager/Items/InventoryManager.cs (2 hunks)
  • Maple2.Server.Game/Manager/MailManager.cs (3 hunks)
  • Maple2.Server.World/Containers/ChannelClientLookup.cs (7 hunks)
🧰 Additional context used
🧠 Learnings (2)
Maple2.Database/Storage/Game/GameStorage.Nurturing.cs (1)
Learnt from: Zintixx
PR: AngeloTadeucci/Maple2#279
File: Maple2.Database/Storage/Game/GameStorage.Wedding.cs:147-159
Timestamp: 2024-10-13T18:10:08.059Z
Learning: In the `GameStorage` class in `Maple2.Database/Storage/Game/GameStorage.Wedding.cs`, the `GetMarriage` method is necessary to properly convert the `Marriage` object and initialize `Partner1` and `Partner2`.
Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (2)
Learnt from: AngeloTadeucci
PR: AngeloTadeucci/Maple2#199
File: Maple2.Server.Game/PacketHandlers/FileHandler.cs:0-0
Timestamp: 2024-10-09T04:13:28.776Z
Learning: Packets can't ever be null inside the `Handle` function of packet handlers in the repository.
Learnt from: AngeloTadeucci
PR: AngeloTadeucci/Maple2#199
File: Maple2.Server.Game/PacketHandlers/FileHandler.cs:0-0
Timestamp: 2024-07-12T04:31:25.376Z
Learning: Packets can't ever be null inside the `Handle` function of packet handlers in the repository.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (12)
Maple2.Database/Storage/Game/GameStorage.Nurturing.cs (1)

22-22: LGTM! Logical improvement to timestamp initialization.

Setting LastFeedTime to the current time when creating a new nurturing record is more appropriate than using DateTime.MinValue. This provides a meaningful baseline for tracking feeding activity.

Maple2.Server.Game/Manager/Items/InventoryManager.cs (1)

463-464: LGTM! Enhanced diagnostic logging.

Adding both item UID and item ID to the error logs and exception messages provides better diagnostic information for debugging item consumption failures. The consistent format across both failure scenarios is well implemented.

Also applies to: 476-477

Maple2.Server.Game/Manager/HousingManager.cs (1)

717-718: LGTM! Improved error handling with graceful failure.

Replacing the exception throw with error logging and returning false provides better stability and controlled error handling. This aligns with the method's boolean return type and prevents unhandled exceptions from crashing the application.

Maple2.Server.Game/Manager/Field/FieldManager/FieldManager.cs (1)

279-284: LGTM! Robust exception handling for packet processing.

The comprehensive exception handling distinguishes between expected IndexOutOfRangeException (logged without stack trace) and unexpected exceptions (logged with full details). Including opcode, account ID, and packet details provides excellent diagnostic information while preventing field crashes from packet processing failures.

Maple2.Server.Game/Manager/MailManager.cs (2)

9-9: LGTM! Added proper logging infrastructure.

Adding Serilog support with a scoped logger provides the foundation for improved error diagnostics throughout the mail management system.

Also applies to: 24-24


211-212: LGTM! Improved error handling with controlled failure.

Replacing the exception throw with error logging and returning MailError.s_mail_error_receiveitem_to_inven provides better stability and aligns with the method's error code return type. The detailed logging includes mail ID and item information for effective debugging.

Maple2.Server.World/Containers/ChannelClientLookup.cs (6)

26-30: Good addition of the Pending state for better channel lifecycle management.

The intermediate state helps prevent race conditions during channel activation.


79-87: The removed attribute was not applicable to value types.

Since channelId is an int (value type), the [NotNullWhen(true)] attribute removal doesn't affect functionality. Value types are never null.


146-146: Correct initialization with Pending status.

Initializing new channels with Pending status aligns with the new lifecycle management approach.


168-174: Proper handling of Pending state transitions.

The monitoring logic correctly allows channels to transition from Pending to either Active or Inactive based on health check results.


265-267: Formatting change only.


272-295: Class relocation follows common C# conventions.

Comment thread Maple2.Server.World/Containers/ChannelClientLookup.cs
@AngeloTadeucci
AngeloTadeucci merged commit 96661ba into master Jul 14, 2025
4 checks passed
@AngeloTadeucci
AngeloTadeucci deleted the dev2 branch July 14, 2025 12:13
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