socketio / socketio/socket.io

Enabling "captureRejections" doesnt work

Open
#4,491 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.