dgofman / nats_client

MIT License
16 stars 1 forks source link

Cannot catch errors in credsAuthenticator #8

Closed MichaelVoelkel closed 10 months ago

MichaelVoelkel commented 10 months ago

Hi,

I use credsAuthenticator. But when things passed into it have the wrong format, an exception is thrown. However, I cannot catch them. The reason will probably be that it's done asynchronously, so it makes some sense. But there should be a way, maybe through some error handler or the exception should be propagated back, I don't know.

It's anyways a bit annoying that I cannot really wait for the connection to be established because await connect will immediately return and the status handler needs to be used...

Any tips? Maybe I'm doing anything wrong?

MichaelVoelkel commented 10 months ago

Ok, I think the issue is that _pongCompleter future is only then-ed and has no catch clause. So the exception goes through the roof and the user has no way to catch it... Are you accepting MRs for this repo currently? I could give it a try.

Because the nasty workaround is to create a CredsAuthenticator before connect, catch exceptions there, and then do not connect. We can just use some fixed nonce if we want to catch certain errors. Or we can really sign a message with the public key to check all... but not ideal and quite hacky.

dgofman commented 10 months ago

If you can replicate the issue and have a solution in mind, please create a Pull Request, and I'll gladly merge your changes. Also, if you need help, I'll need more details. While I'm not currently utilizing CredsAuthenticator, you can explore my demo scripts for reference.

https://github.com/dgofman/nats_client/blob/master/test/setup.sh and https://github.com/dgofman/nats_client/blob/master/test/demo.dart