Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better documentation for catching errors #42

Open
puchm opened this issue May 21, 2021 · 3 comments
Open

Better documentation for catching errors #42

puchm opened this issue May 21, 2021 · 3 comments

Comments

@puchm
Copy link

puchm commented May 21, 2021

I tried to figure out how to catch a connection error which was already mentioned in several other issues. Apparently, the way to do it is:

const emitter = redis();
emitter.state.once('error', () => console.log(error))

This has a problem though: state is not in the type definitions - I just found out about this by looking at the test file. It also took way too long to find out about this so it should be documented in a better way.

I would propose

  1. adding a section to the Readme documenting this
  2. one of the following possibilities regarding state not being in the type defs
    1. Adding state to type defs
    2. Adding a separate function to the type defs, e.g. onError (if you don't want to expose the EventEmitter like that)
    3. Somehow redirecting the events that go to state so that they can be caught with emitter.on.

What do you think would be best?

@mcollina
Copy link
Owner

Can you send a PR to add state to the typedefs?

@puchm
Copy link
Author

puchm commented May 24, 2021

I tried doing that but it seems like it is completely impossible to catch the error.

This is a repo that shows it: https://github.com/puchm/mqemitter-redis-issue
I have patched the typedefs using patch-package for now.

Run npm start. The repo contains the main.ts file. It tries to connect to Redis (which won't work) and then starts a promise which should resolve after 10 seconds. After a few seconds, the Redis connection error gets thrown. The error listener gets executed properly but the execution stops after that. All other asynchronous code is also stopped, as the promise never resolves.

This can crash a server without the dev being able to catch it so we should fix this as soon as possible.

What could be the cause of this?

@puchm
Copy link
Author

puchm commented May 24, 2021

This seems to be related to redis/ioredis#944.

Another possible solution is shown in redis/ioredis#68 and here: https://stackoverflow.com/a/61133867/9144769

I tried finding a solution but I couldn't get any of these to work. Could it be the case that there are calls to the Redis server when initializing the instance, other than the connection? I think there may be calls to redis before the connection is established.

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

No branches or pull requests

2 participants