-
Notifications
You must be signed in to change notification settings - Fork 104
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
Errors from encodeValue_ are not caught and generate a UnhandledPromiseRejectionWarning #1078
Comments
@WaldoJeffers the below snippet worked for me. const q = {
json: true,
sql: 'SELECT * FROM Singers WHERE SingerId=@id',
}
try {
const [rows] = await database.run(q);
console.log(rows.length);
rows.forEach(console.log);
} catch (error) {
console.log('I will get called.')
console.log('Error message => ' + error.message);
}
console.log('Continue execution here...');
|
Hello @AVaksman, Thanks for your answer. Could try the same thing with const q = {
json: true,
params : { id: undefined }, // <-- Add this line (assuming both Singers & SingerId really exist)
sql: 'SELECT * FROM Singers WHERE SingerId=@id',
}
try {
const [rows] = await database.run(q);
console.log(rows.length);
rows.forEach(console.log);
} catch (error) {
console.log('I will get called.')
console.log('Error message => ' + error.message);
}
console.log('Continue execution here...'); This does result in |
Errors in transaction.runStream(..) were not handled by database.runStream(..), which could cause Unhandled Promise Rejections. Fixes googleapis#1078
@WaldoJeffers Would you mind also having a look at #1208? |
Hello @olavloite , Thanks for your PR. It's probably a much better fix than my PR, but I'm not familiar enough with the codebase to provide feedback on the changes 😬 |
* fix: handle potential errors when creating stream Errors in transaction.runStream(..) were not handled by database.runStream(..), which could cause Unhandled Promise Rejections. Fixes #1078 * fix: move error handling to snapshot.runStream * fix: improve stream error handling * test: add tests for parameter encoding * fix: process review comments
Environment details
@google-cloud/spanner
version: 5.1.0Bug description
Errors thrown by common-grpc/service/encodeValue_ like this one (passing
undefined
as value for a named parameter) are never caught by this function's caller, resulting in Unhandled Promise Rejections. Also, for some reason it seems to crash the underlying Node.js process.The error thrown in
encodeValue_
goes all the way toSessionPool.getReadSession
where it fails to be caught:Steps to reproduce
There are probably different ways to reproduce the error; all you have to do is make the
encodeValue_
helper throw. One way to achieve this is to provide anundefined
value to a named parameter in a querySo any attempt to catch the error will fail
But perhaps more unexpectedly, the code will stop running after this line:
I am preparing a PR which might help fix the issue; but wanted to file the issue separately in case you prefer to fix the issue differently.
Thanks for your help :)
The text was updated successfully, but these errors were encountered: