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

_acquire in case of reject return a promise, if this._acquire.promise is used in acquire, in case of reject an exception is raised that is not "captured" by the catch #1592

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

bombjackit
Copy link
Contributor

What this does:

In case of reject acquire raise an exception that is controlled by catch : in previous version the raised exception was not captured from catch and if this node is used inside node-red-contrib-mssql-plus that run on node-red the result is an uncaught exception that stop it.

Related issues:

See this link bestlong/node-red-contrib-mssql-plus#88 (comment)

Pre/Post merge checklist:

  • Update change log

@dhensby
Copy link
Collaborator

dhensby commented Dec 29, 2023

I'm not sure I understand the problem.

At worst it seems the _acquire() function has an inconsistent return type (sometimes a promise, sometimes not), but it is an internal API, so that inconsistency shouldn't matter to any consuming libraries?

Do you have a test or some code to reproduce the problem?

Copy link
Collaborator

@dhensby dhensby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix your commit message. See https://www.conventionalcommits.org/en/v1.0.0/

@bombjackit bombjackit changed the title _acquire in case of reject return a promise, if this._acquire.promise is used in acquire, in case of reject an exception is raised that is not "captured" by the catch fix: _acquire in case of reject return a promise, if this._acquire.promise is used in acquire, in case of reject an exception is raised that is not "captured" by the catch Dec 30, 2023
@bombjackit bombjackit changed the title fix: _acquire in case of reject return a promise, if this._acquire.promise is used in acquire, in case of reject an exception is raised that is not "captured" by the catch _acquire in case of reject return a promise, if this._acquire.promise is used in acquire, in case of reject an exception is raised that is not "captured" by the catch Dec 30, 2023
@bombjackit
Copy link
Contributor Author

bombjackit commented Dec 30, 2023

It is a bit complex to explain, but I’ll try.

All start from here : this is an uncaught exception from node-red

[red] Uncaught Exception:
[error] ConnectionError: Connection not yet open.
at ConnectionPool._acquire (S:.node-red\node_modules\mssql\lib\base\connection-pool.js:380:36)
at ConnectionPool.acquire (S:.node-red\node_modules\mssql\lib\base\connection-pool.js:366:56)
at Immediate. (S:.node-red\node_modules\mssql\lib\tedious\request.js:419:19)
at process.processImmediate (node:internal/timers:476:21)

If you can see all files in this stack trace is from this node (node-mssql), that is used by node-red-contrib-mssql-plus (a node-red node).

Your question maybe is “Why this uncaught exception ? node-red-contrib-mssql-plus must do try catch to avoid this”

See this piece of code

shared.Promise.resolve(this._acquire().promise).catch(err => {
this.emit('error', err)
throw err
})

If _acquire fail it return a reject (that is a promise itself), then you call promise method of a promise object (that does not exist) this fire an uncatchable exception (this.emit is not called for example), because if you use promise you can catch exception only with method catch, not with try … catch.

Another point : it is more clear to return always one type from a method not one randomly selected that depends on what happens without managing each case.

I my environment I had applied the patch with success, when a reject happen a catchable exception was throw (with this.emit inside catch).

For the commit message, I don’t know how to change it, maybe I have to do another pull request ? I saw the web site that you indicated and I learned that I must start my commit message with fix :

@dhensby
Copy link
Collaborator

dhensby commented Jan 4, 2024

For the commit message, I don’t know how to change it, maybe I have to do another pull request ? I saw the web site that you indicated and I learned that I must start my commit message with fix :

$ git commit --amend
$ git push --force

git commit --amend will allow you to change the commit message for a commit, and the git push --force will update your branch and this pull request.

@bombjackit
Copy link
Contributor Author

For the commit message, I don’t know how to change it, maybe I have to do another pull request ? I saw the web site that you indicated and I learned that I must start my commit message with fix :

$ git commit --amend
$ git push --force

git commit --amend will allow you to change the commit message for a commit, and the git push --force will update your branch and this pull request.

Thanks I modified commit message

@dhensby dhensby merged commit f09c23d into tediousjs:master Jan 16, 2024
45 checks passed
Copy link

🎉 This PR is included in version 10.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants