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
fix for #2500 #2505
fix for #2500 #2505
Conversation
I have only tested it with the most minimal example. I suspect we're going to need to iterate on this couple of times. Currently when I run it with the sample file I presented in the #2500 , I get this stacktrace:
Which takes me straight to the beginning of my query in the editor: I am sure you can spot lot of potential problems-I opened this mostly just to present what I have so far. It will certainly need some serious testing to be done. Just let me know if I am going in the right/wrong direction. |
ac5ce0b
to
72347ed
Compare
src/util/make-knex.js
Outdated
@@ -14,6 +14,14 @@ export default function makeKnex(client) { | |||
// The object we're potentially using to kick off an initial chain. | |||
function knex(tableName, options) { | |||
const qb = knex.queryBuilder() | |||
|
|||
if (qb.client.config.asyncStackTraces) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unfortunately won't work for SchemaBuilder
or Raw
since this function is strictly QueryBuilder
.
This should result in that _asyncStack
does not exist in the .then
handler change here for SchemaBuilder
/ Raw
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, I'll add the _asyncStack
generatin for SchemaBuilder and for Raw too. Thanks!
72347ed
to
a28603a
Compare
a28603a
to
05bebc0
Compare
@wubzz I've added it to all three constructors-so the async stack trace gets saved for |
@capaj Looks fine to me. I would have preferred an integration test for when Node >= 8, but I guess at the same time this is just a hack to bypass what boils down to a Node/V8 issue, so maybe doesn't matter too much. |
src/interface.js
Outdated
|
||
if (this.client.config.asyncStackTraces) { | ||
result.catch((err) => { | ||
err.originalStack = err.stack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be wrong, but shouldn't it also throw here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did try both and it seems we don't want to throw.
Without throw, when I run this code:
const test = async () => {
try {
await db('jijoi').select()
} catch (err) {
console.log('caught')
}
console.log('can be caught')
}
test()
I get this:
caught
can be caught
but when I add the throw there:
caught
can be caught
Unhandled rejection error: relation "jijoi" does not exist
at test (/home/capaj/git_projects/tests/knex.js:18:11)
at Object.<anonymous> (/home/capaj/git_projects/tests/knex.js:25:1)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Function.Module.runMain (module.js:690:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:666:3
There's that unhandled rejection.
When I don't throw, it behaves well even when I don't try-catch:
const test = async () => {
await db('jijoi').select()
console.log('does not run')
}
test()
outputs:
Unhandled rejection error: relation "jijoi" does not exist
at test (/home/capaj/git_projects/tests/knex.js:17:9)
at Object.<anonymous> (/home/capaj/git_projects/tests/knex.js:21:1)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Function.Module.runMain (module.js:690:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:666:3
(node:31738) UnhandledPromiseRejectionWarning: error: relation "jijoi" does not exist
at test (/home/capaj/git_projects/tests/knex.js:17:9)
at Object.<anonymous> (/home/capaj/git_projects/tests/knex.js:21:1)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Function.Module.runMain (module.js:690:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:666:3
(node:31738) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:31738) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has got to do with the fact that knex does not return a real promise-it just has methods then
and catch
so it's masquerading like a promise, but it's really not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @wubzz was right that it should throw. Now this extra catch is just added as an additional branch how result is resolved.
So instead of adding this new .catch(..)
handler as a separate branch which is then left dangling without having reference to the returned promise, it should be added like this:
result = result.catch(...)
05bebc0
to
10d8d9d
Compare
I'm fine with merging this given explanation above. @elhigu Ok for you too? |
It's failing in the tests-I will fix it in the afternoon |
c743aeb
to
5c74cf4
Compare
feel free to install it via |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking long with this. I started work on new project that has nothing to do with javascript so I have lot less time to put in knex issues (I still have at least 10h/month though :) ).
src/interface.js
Outdated
|
||
if (this.client.config.asyncStackTraces) { | ||
result.catch((err) => { | ||
err.originalStack = err.stack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @wubzz was right that it should throw. Now this extra catch is just added as an additional branch how result is resolved.
So instead of adding this new .catch(..)
handler as a separate branch which is then left dangling without having reference to the returned promise, it should be added like this:
result = result.catch(...)
5c74cf4
to
2eb2669
Compare
@elhigu added the throw as requested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Integration test would have been good to add, but I don’t see it that necessary in this PR.
@elhigu I will try to make them run on my machine and add some when I have some spare time in the coming weeks. I've only added unit tests because those were easy to run without setting up any databases. |
So is this PR actually going to be accepted? |
@jpike88 well last event was about capaj was going to try to add integration test, and after that the new configuration options must be documented too. After that this is good to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs related documentation PR
@elhigu I'll add that documentation PR this evening. I can try adding integration test, but I currently get this error:
is there any documentation on how to set up an environment for knex integration tests @elhigu ? |
Im trying to include this in my project and having major issues... I'm using the esm module and its saying require(...) is not a function. Isn't it as simple as just running npm install && npm build in the folder first? |
here's the doc PR: knex/documentation#104 |
Requesting that a new release is made just to get this out there, it's going to be so damn useful |
@capaj for mysql/mariadb you just need to setup mysql server and create knex_test database and has access there with user root without password. Database called knex_test is pretty much the only thing that every DB needs for being able to ran the tests against them. tests/knexfile.js has all the connection details how each DB is connected during the tests. But if you want to run tests just for some databases you can use DB="postgres sqlite" npm run test in contributing.md is some stuff about how to setup postgres tables. I suppose that would be good if I add some docker-compose file for setting up all databases for running tests. |
@elhigu thanks-I'll try to setup those docker images. |
https://github.com/tgriesser/knex/blob/master/scripts/stress-test/docker-compose.yml there is already docker-compose file, but ports / usernames etc. should be changed and knex_test databases created for running normal tests against them. |
2eb2669
to
cb00544
Compare
@elhigu added those integration tests here: cb00544#diff-bfeb3d958a56cecbae4f5f8983fdf195R713 |
@elhigu do you still miss anything or can you merge this as is? |
That might be unstable, but lets see if it blows in future and thinks better way to do it then. I'll give this final review now :) |
Tests probably should have still checked that this work for transactions too. But we'll find it out soon enough. |
Awesome. @elhigu don’t want to sound pushy, do you have an rough eta of the next release? |
@jpike88 when I have time at some point, pretty soon |
@elhigu one month later... |
@elhigu bump... are you the only person who is authorised to handle releases? if so, any idea on an eta? no pressure, I'd just fork and build it myself but there doesn't seem to be clear instructions on a build process. |
@jpike88 yes there are various persons who has rights. Bumping this repetitively actually sounds a bit like pressuring. I'm going to do some other stuff first before doing the next release that will be 0.15.0. Eta is definitely before september or maybe next week. This is not that critical issue that I would rush releasing just for this one. |
Is there an easy build guide or something in case I want to be more cutting edge? Would be nice if knex had a beta track or something |
@jpike88 it is published namespaced on |
Awesome, thanks |
can someone please tell me where to put the config file? i tried below but it still not working
|
@chaintng that should work. It's a bit late now, but let me know if you still have issues-I'll gladly look into it. |
knex#2505 in the knex repo
slightly nasty way of getting better error stacks when using async/await.
Toggles on by setting a new config parameter called:
asyncStackTraces
to true