/node_modules/pg-promise/lib/errors/queryResult.js:151
gap1 + 'code: queryResultErrorCode.' + errorMessages[this.code].name,
^
TypeError: Cannot read property 'name' of undefined
db.one('SELECT * FROM users WHERE id = $1', 1)
How do you get this type of error?
You can't get it simply by executing that query. Need to see more context.
Also, which pg-promise version are you using?
db.one('SELECT * FROM users WHERE id = $1', 1)
Shouldn't this line be like at the bottom?
db.one('SELECT * FROM users WHERE id = $1', [1])
@anonrig not sure what you mean by that...
The second parameter of the function db.one can it be an integer or should it be an array, in order to parse $1 to its corresponding value?
@anonrig it works either way.
version: 6.2.1
export function getById(id) {
return db.one('SELECT * FROM users WHERE id = $1', id)
}
@kmarchenko I can execute the same type of query, with all possible result/error types, but I never get the type of error you described. There must be something else going. Can you show the code that calls it?
Also, when you get the error, try to log the following:
console.log(error.code);
@vitaly-t
db.connect().then(() => {
console.log('[INFO] Successful database connection!')
db.one('SELECT * FROM users WHERE id = $1', 123).then(console.log).catch(error => console.log(error.code))
}).catch((error) => {
console.log('[DB ERROR]: ', error.message || error)
})
[INFO] Successful database connection!
node_modules/pg-promise/lib/errors/queryResult.js:151
gap1 + 'code: queryResultErrorCode.' + errorMessages[this.code].name,
^TypeError: Cannot read property 'name' of undefined
at QueryResultError.toString (node_modules/pg-promise/lib/errors/queryResult.js:151:76)
at Function.prepareStackTrace (node_modules/source-map-support/source-map-support.js:372:16)
at Function.captureStackTrace ()
at new QueryResultError (node_modules/pg-promise/lib/errors/queryResult.js:123:15)
at Result.ctx.db.client.query (node_modules/pg-promise/lib/query.js:164:45)
at Result.Query.handleReadyForQuery (node_modules/pg/lib/query.js:144:10)
at Connection.(node_modules/pg/lib/client.js:180:19)
at emitOne (events.js:101:20)
at Connection.emit (events.js:189:7)
at Socket.(node_modules/pg/lib/connection.js:133:12)
error Command failed with exit code 1.
When I run exactly this code, I'm getting:
[INFO] Successful database connection!
0
You are going to need to debug this a little further yourself, as I cannot see how this type of error is even possible. I can't reproduce it, even with your own code.
@kmarchenko the only way such an error can happen, is if we try to hack the error class toString method, by doing this:
error.toString.call({});
the code above makes direct string conversion on the invalid context.
The thing is, there is no such situation inside pg-promise anywhere, so I cannot fathom how this can possibly happen.
I'm beginning to assume something else is wrong with your app, like maybe there is some dumb library, like newrelic, trying to hack into toString or Error implementations.
I have no other explanation. You will need to investigate this on your end, as I have done everything I could think of at this point.
@vitaly-t I'm downgraded pg-promise version to 5.9.0, and all is fine. I have no idea too, when I tried to debug vars in QueryResultError, I just get undefined on all vars.
@kmarchenko what version of Node.js are you using?
@kmarchenko also, could you, please try 2 specific versions: 6.0.24 and 6.0.25. There was a change between those two, which I suspect may somehow contribute to the problem. If that's the case, then it will work for you with v6.0.24, but not with v6.0.25. That's just the best guess right now.
Also, I wonder what happens when you create such an error object yourself, directly:
const error = new pgp.errors.QueryResultError(0, {rows: []}, 'select', 1);
console.log(error);
because that's what seemingly results in creation of an invalid error object, which is very strange.
A related question has been asked on StackOverflow: https://stackoverflow.com/questions/44850862/custom-es6-javascript-error-issue
@kmarchenko created branch error-test specially for you to try it, and see if the issue is gone.
Really need some feedback from you, man!
@vitaly-t
node version: v7.6.0
With v6.0.24 all works fine, with v6.0.25 crashes.
const error = new pgp.errors.QueryResultError(0, {rows: []}, 'select', 1);
console.log(error);
v6.0.24
QueryResultError {
code: queryResultErrorCode.noData
message: "No data returned from the query."
received: 0
query: "select"
values: 1
}
v6.0.25 error
node_modules/pg-promise/lib/errors/queryResult.js:151
gap1 + 'code: queryResultErrorCode.' + errorMessages[this.code].name,
TypeError: Cannot read property 'name' of undefined
With error-test branch all works fine.
@kmarchenko thank you! Than means most likely if you pull it from branch error-test, it should work. Have you tried though?
@vitaly-t Yes, I tried it and it work.
Ok, cool, we are getting somewhere. I'm preparing one last test for you to see if it works, and then I can apply the fix to the master. Give me 10 mins, please ;)
@kmarchenko could you, please, run your test against branch error-test-2, and tell me if it works!
Thank you!!!
P.S. This is the last one, I promise! ;)
@vitaly-t Updated, but unfortunately old error returns back.
@kmarchenko Thank you!
I honestly still do not understand how the error you are getting is even possible. But still, based on your results, I'm going to revert the master to the version that's in error-test, and re-release it shortly (within an hour).
Thank you for finding and reporting the issue, and if you somehow stumble upon the reason of why this was happening, please let me know.
@vitaly-t Okay, I'll let you know. Thank!
@kmarchenko the issue has been fixed in Version 6.2.3. Please re-test, and if all is good - close the issue.
Thank you for your help!
@vitaly-t Everything works. Thank you.
Just a note if anyone else still sees similar errors (version: 6.3.1)
You get the error bellow if you are using bluebird somewhere in the chain and have not set pg-promise to use bluebrid. At least in my case.
TypeError: Cannot set property 'name' of undefined
at QueryResultError (node_modules/pg-promise/lib/errors/queryResult.js:122:27)
at process._tickCallback (internal/process/next_tick.js:109:7)
@kmarchenko Is this what was happening? -
You get the error bellow if you are using bluebird somewhere in the chain and have not set pg-promise to use bluebrid
@redben thank you!