solana-labs / solana-web3.js

Solana JavaScript SDK
https://solana-labs.github.io/solana-web3.js
MIT License
2.1k stars 845 forks source link

Error: Uncaught rejection on RPC request #3236

Open iprotoni opened 1 week ago

iprotoni commented 1 week ago

Overview

Whenever an RPC request encounters an error, it results in an uncaught rejection. This means that even if the outer call is wrapped in a try-catch block, the error cannot be caught and handled properly.

Steps to reproduce

  1. Make an RPC request using the solana-web3.js library.
  2. Force an error condition for the request.
  3. Wrap the request call in a try-catch block.
  4. Observe that the error is not caught by the try-catch block and results in an uncaught rejection.

Description of bug

There is an issue in the packages/library-legacy/src/connection.ts file at line 1679. Whenever an RPC request encounters an error, it results in an uncaught rejection. This means that even if the outer call is wrapped in a try-catch block, the error cannot be caught and handled properly.

Expected Behavior:

The error should be caught and handled properly within the try-catch block surrounding the RPC request call.

Actual Behavior:

The error results in an uncaught rejection, bypassing the try-catch block.

Proposed Solution:

Add a try-catch block around the RPC request in packages/library-legacy/src/connection.ts at line 1679 to handle errors properly and prevent uncaught rejections.

buffalojoec commented 1 week ago

Duplicate of #2933. As mentioned in the discussion on #2933, we'll need a true reproduction of the issue. I wasn't able to repro with a test.

It's also possible it's not related to Web3.js, but rather the callback function from a dependency. See discussion here.