Enabling "captureRejections" doesnt work
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 63.2k
- Forks
- 10.3k
- Avg merge
- 11d 20h
- Merged PRs (30d)
- 2
Description
Describe the bug
According to https://socket.io/docs/v4/listening-to-events/#error-handling it is possible to capture errors thrown in events by enabling captureRejections but doesn't seem to work. Is this example up to date? If this is no longer possible, is there a way to "capture" all errors thrown inside events at one location?
To Reproduce
Please fill the following code example:
Socket.IO server version: 4.5.1
Server
import { Server } from "socket.io";
require("events").captureRejections = true;
const io = new Server(3000, {});
io.on("connection", (socket) => {
console.log(`connect ${socket.id}`);
socket.on("disconnect", () => {
console.log(`disconnect ${socket.id}`);
});
socket[Symbol.for("nodejs.rejection")] = (err) => {
console.log("error catched", err);
};
});
Expected behavior
Error should be catched by "socket[Symbol.for("nodejs.rejection")]"
Additional context
I am trying to built a proper errorHandler and dont want to try/catch everywhere but just have a central errorHandler "captureRejections" seemed like a good solution but sadly the documentation isnt very clear on how to implement this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the linked listening-to-events error-handling documentation and reproduce the supplied Socket.IO 4.5.1 server example using Node.js captureRejections. Check whether the documented Symbol.for("nodejs.rejection") handler is reached; done means establishing the supported behavior and updating the documentation or issue guidance accordingly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100