Skip to content

TypeError: Cannot read property 'query' of undefined #1024

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

Closed
wormen opened this issue Mar 10, 2015 · 4 comments
Closed

TypeError: Cannot read property 'query' of undefined #1024

wormen opened this issue Mar 10, 2015 · 4 comments
Assignees
Labels

Comments

@wormen
Copy link

wormen commented Mar 10, 2015

error text

/node_www/crawler.x-sells.com/node_modules/mysql/lib/protocol/Parser.js:82
        throw err;
              ^
TypeError: Cannot read property 'query' of undefined
    at /node_www/crawler.x-sells.com/autoInit.js:53:19
    at Handshake.onConnect (/node_www/crawler.x-sells.com/node_modules/mysql/lib/Pool.js:54:9)
    at Handshake.Sequence.end (/node_www/crawler.x-sells.com/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
    at Handshake.ErrorPacket (/node_www/crawler.x-sells.com/node_modules/mysql/lib/protocol/sequences/Handshake.js:103:8)
    at Protocol._parsePacket (/node_www/crawler.x-sells.com/node_modules/mysql/lib/protocol/Protocol.js:271:23)
    at Parser.write (/node_www/crawler.x-sells.com/node_modules/mysql/lib/protocol/Parser.js:77:12)
    at Protocol.write (/node_www/crawler.x-sells.com/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/node_www/crawler.x-sells.com/node_modules/mysql/lib/Connection.js:82:28)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:529:20)

windows on everything works fine, but when you transfer linux appears this error
tell me how it is solved

@dougwilson dougwilson self-assigned this Mar 10, 2015
@dougwilson
Copy link
Member

It really depends on what your code in the /node_www/crawler.x-sells.com/autoInit.js file is.

@dougwilson
Copy link
Member

Most likely you have code like

pool.getConnection(function (err, conn) {
  conn.query(/* ... */);
})

which is not correct, because you never checked and acted on err.

@wormen
Copy link
Author

wormen commented Mar 10, 2015

@dougwilson No, the connection I have so

db = mysql.createPool({
             connectionLimit : $config.get('db:connectionLimit'),
             host      : $config.get('db:host'),
             user      : $config.get('db:user'),
             database  : $config.get('db:base'),
             password  : $config.get('db:password')
         })

using so

db.getConnection(function (err, connection) {
            connection.query(/* ... */, [], callback);
            connection.release();
        });

but the problem is this only in Linux, and it is not always

@dougwilson
Copy link
Member

Thanks :) Your second code block is incorrect. It should be as follows:

db.getConnection(function (err, connection) {
      if (err) throw err; // You *MUST* handle err and not continue execution if
                          // there is an error. this is a standard part of Node.js
            connection.query(/* ... */, [], callback);
            connection.release();
        });

@mysqljs mysqljs locked and limited conversation to collaborators Jun 30, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants