Skip to content

fix: add UI brand name and enhance error handling in ConnectionFactory and server process#31

Merged
muddlebee merged 2 commits intodevfrom
net-server
Aug 9, 2025
Merged

fix: add UI brand name and enhance error handling in ConnectionFactory and server process#31
muddlebee merged 2 commits intodevfrom
net-server

Conversation

@muddlebee
Copy link
Copy Markdown
Member

@muddlebee muddlebee commented Aug 6, 2025

  • Improved error handling in the ConnectionFactory by wrapping event handlers for 'connected', 'disconnected', and 'error' events in try-catch blocks. This change ensures that any exceptions thrown during these events are logged without disrupting the connection process, enhancing the robustness of the connection management.
  • Added process-level error handlers in the server to manage unhandled promise rejections and uncaught exceptions. This addition prevents the application from crashing due to WebSocket-related errors, allowing it to continue operating in a resilient manner while logging critical issues for further investigation.
  • These modifications aim to improve the overall stability and maintainability of the application by ensuring that error scenarios are handled gracefully, thus providing a better user experience during network fluctuations.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling to prevent unhandled exceptions from causing unexpected crashes during network events.
    • Enhanced server resilience by handling WebSocket disconnection errors gracefully, avoiding unnecessary server restarts.
  • Chores

    • Added global error handlers to log and manage unexpected errors and promise rejections at the server level.

- Improved error handling in the ConnectionFactory by wrapping event handlers for 'connected', 'disconnected', and 'error' events in try-catch blocks. This change ensures that any exceptions thrown during these events are logged without disrupting the connection process, enhancing the robustness of the connection management.
- Added process-level error handlers in the server to manage unhandled promise rejections and uncaught exceptions. This addition prevents the application from crashing due to WebSocket-related errors, allowing it to continue operating in a resilient manner while logging critical issues for further investigation.
- These modifications aim to improve the overall stability and maintainability of the application by ensuring that error scenarios are handled gracefully, thus providing a better user experience during network fluctuations.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 6, 2025

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 56dcf76 and 4a13a85.

📒 Files selected for processing (2)
  • packages/api/services/network/ConnectionFactory.ts (1 hunks)
  • packages/api/src/server.ts (1 hunks)
 _________________________________________________
< If you only knew now what you didn't know then. >
 -------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting in your project's settings in CodeRabbit to disable sequence diagrams in the walkthrough.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch net-server

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

Support

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

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.

Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR implements defensive error handling to improve the stability of WebSocket connections and prevent server crashes in the Swush application. The changes focus on two main areas: enhanced error handling in the ConnectionFactory and process-level error management in the server.

In the ConnectionFactory, all event handlers for API connections (connected, disconnected, error) and WebSocket events (close, error) are now wrapped in try-catch blocks. This prevents exceptions thrown during these events from propagating up and potentially crashing the connection management process. The approach ensures that connection state management continues to function even when individual event handlers encounter errors.

At the server level, global process handlers for unhandledRejection and uncaughtException events have been added. These handlers attempt to differentiate between WebSocket-related errors (which the application should survive) and truly fatal errors (which should still cause process termination). The implementation uses string matching to identify WebSocket errors and allows the server to continue operating when these specific errors occur.

This defensive programming approach fits into the broader architecture of a blockchain application that heavily relies on WebSocket connections to multiple Polkadot networks. Given that network instability is common in blockchain environments, maintaining service availability during temporary connection issues is crucial for user experience. The changes complement the existing connection management infrastructure in the packages/api/services/network/ directory, which includes connection pooling, endpoint management, and resilience features.

Important Files Changed

Files Modified
Filename Score Overview
packages/api/services/network/ConnectionFactory.ts 4/5 Added try-catch blocks around all event handlers to prevent connection disruption
packages/api/src/server.ts 2/5 Implemented process-level error handlers with string-based WebSocket error detection

Confidence score: 3/5

  • This PR addresses real stability concerns but introduces potential issues with error masking and fragile error detection logic
  • Score reflects the defensive approach benefits balanced against the risks of suppressing exceptions and unreliable string-based error matching
  • Pay close attention to packages/api/src/server.ts for the process-level error handling implementation

Sequence Diagram

sequenceDiagram
    participant User
    participant Server as Express Server
    participant CF as ConnectionFactory
    participant API as Polkadot API
    participant WS as WebSocket
    participant Process as Node Process

    User->>Server: "Start Application"
    
    Note over Process: Process-level error handlers setup
    Process->>Process: "Setup unhandledRejection handler"
    Process->>Process: "Setup uncaughtException handler"
    
    Server->>Server: "Initialize SDK"
    Server->>CF: "createHydradxConnection(endpoint, callback)"
    
    CF->>WS: "Create WsProvider"
    CF->>API: "Create ApiPromise"
    API->>CF: "API ready"
    
    Note over CF: Enhanced event handling with try-catch
    CF->>API: "Setup event handlers (connected, disconnected, error)"
    CF->>WS: "Setup WebSocket event handlers"
    CF->>CF: "Perform stability check"
    CF->>Server: "Connection established"
    
    alt Connection Error Occurs
        WS->>CF: "WebSocket error/close event"
        Note over CF: Try-catch wrapped handler
        CF->>CF: "Log error safely"
        CF->>Server: "onConnectionEvent('error', error)"
        Server->>Server: "Log connection issue"
    end
    
    alt Unhandled Promise Rejection
        API-->>Process: "Promise rejection"
        Process->>Process: "Log rejection reason"
        Process->>Process: "Continue operation (no exit)"
    end
    
    alt Uncaught Exception
        WS-->>Process: "WebSocket-related exception"
        Process->>Process: "Check if WebSocket-related"
        alt WebSocket Error
            Process->>Process: "Log warning, continue operation"
        else Fatal Error
            Process->>Process: "Log fatal error"
            Process->>Process: "Graceful shutdown (exit 1)"
        end
    end
    
    User->>Server: "API Request"
    Server->>CF: "validateConnection()"
    CF->>API: "Perform validation query"
    
    alt Validation Fails
        API-->>CF: "Query timeout/error"
        CF->>CF: "Log validation failure"
        CF->>Server: "Return false"
        Server->>User: "Service degraded response"
    else Validation Success
        CF->>Server: "Return true"
        Server->>User: "Normal response"
    end
Loading

2 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

@muddlebee
Copy link
Copy Markdown
Member Author

bugbot run

@cursor
Copy link
Copy Markdown

cursor bot commented Aug 6, 2025

🚨 Bugbot Trial Expired

Your Bugbot trial has expired. Please purchase a license in the Cursor dashboard to continue using Bugbot.

@muddlebee
Copy link
Copy Markdown
Member Author

@greptile-ai

Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This review covers only the changes made since the last review (commit 4a13a85), not the entire PR.

The latest changes to this PR introduce a purely cosmetic UI enhancement that appears unrelated to the stated purpose of improving error handling. The only file modified in this latest commit is apps/web/src/app/page.tsx, which adds a Swush logo to the top-left corner of the main swap page.

This change integrates with the existing Next.js web application by using the Next.js Image component for optimized logo rendering. The logo is positioned absolutely with responsive design classes and proper accessibility attributes. The implementation follows standard React/Next.js patterns and fits within the existing component structure of the swap page.

However, this UI modification is completely disconnected from the PR's described focus on ConnectionFactory error handling and server process improvements, suggesting either a mixed commit, incorrect PR description, or changes that should be in a separate PR focused on branding/UI enhancements.

Important Files Changed

Files Changed
Filename Score Overview
apps/web/src/app/page.tsx 4/5 Added Swush logo to top-left corner of swap page using Next.js Image component

Confidence score: 4/5

  • This latest change is safe to merge with minimal risk as it's a simple UI addition
  • Score reflects that while the code is clean and functional, it's unrelated to the PR's stated purpose which creates confusion
  • No files require special attention as this is a straightforward logo addition

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@muddlebee muddlebee changed the title fix: enhance error handling in ConnectionFactory and server process fix: add UI brand name and enhance error handling in ConnectionFactory and server process Aug 7, 2025
@muddlebee muddlebee merged commit 9980fd2 into dev Aug 9, 2025
2 checks passed
@muddlebee muddlebee deleted the net-server branch September 27, 2025 11:24
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