Vincit/db-errors

DBError/parser.js: TypeError: Cannot read property 'length' of undefined

Closed this issue ยท 4 comments

Hi,

I am writing a NodeJS + React app with MySQL 5.7 using Objection 2.1.3 (which is using db-errors:0.2.3) and today I ran into a weird issue which I don't know how to debug or reproduce locally.

I don't really know how to explain this thoroughly but also didn't know where else to write about this.

So up until now I've developed the app locally with the local DB and everything works fine. And if it doesn't, all the errors are clear enough.
For debugging Knex errors (v 0.21.1), I set the DEBUG env var to 'knex:*' and it helps me a lot. But now I ran into an error and knex debugging doesn't help me because as I understand, the code doesn't reach knex at all.

The problem is that this issue appeared when I was trying to deploy the app with a docker image on my employer's internal container platform. The deployment itself works well, app starts up and everything. But when making any action that should connect to the database, it fails with an error and I can't reproduce it on my local machine.
But the MySQL database is deployed on another in-house Infrastructure-as-a-Service platform and it seems it isn't able to connect properly. I think it might be an issue of the DB user not having proper access rights, but I'm not sure. I am contacting respective support channels as well but I also wanted to write here and ask what could cause this problem and if it can somehow be more descriptive?

The exact error that I get is this:

(node:11) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at Object.parse (/usr/src/app/node_modules/db-errors/lib/parsers/mysql/DBError/parser.js:11:23)
at parse (/usr/src/app/node_modules/db-errors/lib/dbErrors.js:27:21)
at wrapError (/usr/src/app/node_modules/db-errors/lib/dbErrors.js:16:20)
at handleExecuteError (/usr/src/app/node_modules/objection/lib/queryBuilder/QueryBuilder.js:1494:32)
at QueryBuilder.execute (/usr/src/app/node_modules/objection/lib/queryBuilder/QueryBuilder.js:685:13)
at process._tickCallback (internal/process/next_tick.js:68:7)

Thanks!

For some reason the error had an sqlState field but it was undefined. Fixed in my local branch. Will push soon.

@koskimas any chance you could take a look at it again and push your local changes, please? ๐Ÿ˜…

For anyone else dealing with this -- I am encountering this error as well. While reproducing it is a bit tricky (working on it), I can see the code and can indeed confirm that sqlState is undefined for some reason.

For some reason the error had an sqlState field but it was undefined. Fixed in my local branch. Will push soon.

This 100% the reason, as for why this occurred is up in the air.

@koskimas I see that last year your committed to master but never tagged a version, I believe that the changes in master 7258cf0#diff-39c9809bf2882e99aef57953b943f55b6b397ec20f6da34ba57044a56c75c8c3R8 should resolve this issue -- the fix is there! What are the chances this can go out? If not maybe just make a small fix version that only includes this fix?

Hi guys, this bug still exists. Did you find a solution? Last db-errors package isn't updated with this fix
Also, do you understand why this error occurs? For me it happens randomly in different query, also on select * queries.