Open karlhorky opened 7 years ago
At the moment, in the real world, you have to wrap the client.connect
call into a try / catch block anyway, because there are other scenarios where the client will throw synchronously (for example if the username is empty), even if you attached an error handler to it (client.on("error", ...)
). But I agree that it would be more consistent if those synchronous errors would be thrown through the client error
handler.
@mscdex I could create a PR that essentially surrounds the client.connect code with a try/catch block and emits the "error" event rather than throwing directly. I would make sure that the error message follows the current design and throws with a meaningful "level" property. Any objections?
The problem is that there is no way to distinguish between an encrypted key and a corrupt unencrypted key, so I'm not sure that there is much that can be done here.
I think even the messages that are in lib/utils.js already are much better than the messages from node-asn1
:
errMsg = 'Malformed private key (expected sequence)';
if (keyInfo._decrypted)
errMsg += '. Bad passphrase?';
Maybe these can just be thrown in a catch
block?
Given an encrypted private key and an incorrect passphrase, obscure error messages are thrown from the
node-asn1
library:Long, non-empty, incorrect passphrase
Empty, incorrect passphrase
This appears to be as a result of
asnReader.readSequence()
andasnReader.readInt()
throwing here and here and not being caught in lib/utils.js.Would it make sense to wrap these (and maybe other calls to
node-asn1
methods) intry / catch
blocks?