NodeJS server crashes when querying MySQL database with “Incorrect arguments” to throw error
up vote
0
down vote
favorite
While trying to query a local MySQL database, I encounter the following error:
..servernode_modulesmysqllibprotocolParser.js:80
throw err; // Rethrow non-MySQL errors
^
Incorrect arguments
No further information is provided after that.
I've looked up the already available solutions such as adding:
con.on('error', function(err)
console.log("[mysql error]",err);
);
or even replacing (the only) throw err
in the code with console.log(err);
but none did the trick.
The server eventually crashes once the error is displayed, and it happens after the console.log('Query res: ', results);
in the code below, meaning that the request has been successful and has fetched the wanted data.
As I see it, it could be caused by bcrypt, but the error comes from the MySQL node.js package as seen in the logs.
loginroutes.js:
exports.login = function(req, res)
console.log("email:", req.body.email, "password:", req.body.password);
var email = req.body.email;
var password = req.body.password;
con.query("SELECT * FROM users WHERE email = ?", [email], (err, results) =>
if (err)
console.log("Error ocurred");
res.send("code":400, "failed":"error occurred");
else
console.log('Query res: ', results);
if (results.length > 0)
if (bcrypt.compareSync(results.password, password))
res.send("code":200, "success":"login successful");
else
res.send("code":204, "success":"email & password combination does not match");
else
res.send("code":204, "success":"email does not exist");
);
;
What is it I missed and what can I do to solve that issue ?
Thank you.
EDIT: also tried with SELECT * FROM users WHERE email = "" + email + """
just for the sake of it, it turns out similar to the previous request.
mysql node.js server crash
|
show 1 more comment
up vote
0
down vote
favorite
While trying to query a local MySQL database, I encounter the following error:
..servernode_modulesmysqllibprotocolParser.js:80
throw err; // Rethrow non-MySQL errors
^
Incorrect arguments
No further information is provided after that.
I've looked up the already available solutions such as adding:
con.on('error', function(err)
console.log("[mysql error]",err);
);
or even replacing (the only) throw err
in the code with console.log(err);
but none did the trick.
The server eventually crashes once the error is displayed, and it happens after the console.log('Query res: ', results);
in the code below, meaning that the request has been successful and has fetched the wanted data.
As I see it, it could be caused by bcrypt, but the error comes from the MySQL node.js package as seen in the logs.
loginroutes.js:
exports.login = function(req, res)
console.log("email:", req.body.email, "password:", req.body.password);
var email = req.body.email;
var password = req.body.password;
con.query("SELECT * FROM users WHERE email = ?", [email], (err, results) =>
if (err)
console.log("Error ocurred");
res.send("code":400, "failed":"error occurred");
else
console.log('Query res: ', results);
if (results.length > 0)
if (bcrypt.compareSync(results.password, password))
res.send("code":200, "success":"login successful");
else
res.send("code":204, "success":"email & password combination does not match");
else
res.send("code":204, "success":"email does not exist");
);
;
What is it I missed and what can I do to solve that issue ?
Thank you.
EDIT: also tried with SELECT * FROM users WHERE email = "" + email + """
just for the sake of it, it turns out similar to the previous request.
mysql node.js server crash
There could be an escaping issue with the mail address. Can you try with"SELECT * FROM users WHERE email = " + mysql.escape(email)
instead
– Berkays
Nov 10 at 15:33
putreturn
keyword before res.send.return res.send("code":400, "failed":"error occurred");
– front_end_dev
Nov 10 at 15:44
@Berkays that solved the crash issue, but for some reasonresults
appears empty when logged (it wasn't previously). What could be the reason behind it ?
– ilomax
Nov 10 at 17:00
@front_end_dev I added areturn
before everyres.send()
as you suggested and now the server crashes just by reloading the login page.
– ilomax
Nov 10 at 17:03
@ilomax does the query work as expected if you execute it directly in mysql interface?
– Berkays
Nov 10 at 17:43
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
While trying to query a local MySQL database, I encounter the following error:
..servernode_modulesmysqllibprotocolParser.js:80
throw err; // Rethrow non-MySQL errors
^
Incorrect arguments
No further information is provided after that.
I've looked up the already available solutions such as adding:
con.on('error', function(err)
console.log("[mysql error]",err);
);
or even replacing (the only) throw err
in the code with console.log(err);
but none did the trick.
The server eventually crashes once the error is displayed, and it happens after the console.log('Query res: ', results);
in the code below, meaning that the request has been successful and has fetched the wanted data.
As I see it, it could be caused by bcrypt, but the error comes from the MySQL node.js package as seen in the logs.
loginroutes.js:
exports.login = function(req, res)
console.log("email:", req.body.email, "password:", req.body.password);
var email = req.body.email;
var password = req.body.password;
con.query("SELECT * FROM users WHERE email = ?", [email], (err, results) =>
if (err)
console.log("Error ocurred");
res.send("code":400, "failed":"error occurred");
else
console.log('Query res: ', results);
if (results.length > 0)
if (bcrypt.compareSync(results.password, password))
res.send("code":200, "success":"login successful");
else
res.send("code":204, "success":"email & password combination does not match");
else
res.send("code":204, "success":"email does not exist");
);
;
What is it I missed and what can I do to solve that issue ?
Thank you.
EDIT: also tried with SELECT * FROM users WHERE email = "" + email + """
just for the sake of it, it turns out similar to the previous request.
mysql node.js server crash
While trying to query a local MySQL database, I encounter the following error:
..servernode_modulesmysqllibprotocolParser.js:80
throw err; // Rethrow non-MySQL errors
^
Incorrect arguments
No further information is provided after that.
I've looked up the already available solutions such as adding:
con.on('error', function(err)
console.log("[mysql error]",err);
);
or even replacing (the only) throw err
in the code with console.log(err);
but none did the trick.
The server eventually crashes once the error is displayed, and it happens after the console.log('Query res: ', results);
in the code below, meaning that the request has been successful and has fetched the wanted data.
As I see it, it could be caused by bcrypt, but the error comes from the MySQL node.js package as seen in the logs.
loginroutes.js:
exports.login = function(req, res)
console.log("email:", req.body.email, "password:", req.body.password);
var email = req.body.email;
var password = req.body.password;
con.query("SELECT * FROM users WHERE email = ?", [email], (err, results) =>
if (err)
console.log("Error ocurred");
res.send("code":400, "failed":"error occurred");
else
console.log('Query res: ', results);
if (results.length > 0)
if (bcrypt.compareSync(results.password, password))
res.send("code":200, "success":"login successful");
else
res.send("code":204, "success":"email & password combination does not match");
else
res.send("code":204, "success":"email does not exist");
);
;
What is it I missed and what can I do to solve that issue ?
Thank you.
EDIT: also tried with SELECT * FROM users WHERE email = "" + email + """
just for the sake of it, it turns out similar to the previous request.
mysql node.js server crash
mysql node.js server crash
edited Nov 10 at 18:30
asked Nov 10 at 15:24
ilomax
148114
148114
There could be an escaping issue with the mail address. Can you try with"SELECT * FROM users WHERE email = " + mysql.escape(email)
instead
– Berkays
Nov 10 at 15:33
putreturn
keyword before res.send.return res.send("code":400, "failed":"error occurred");
– front_end_dev
Nov 10 at 15:44
@Berkays that solved the crash issue, but for some reasonresults
appears empty when logged (it wasn't previously). What could be the reason behind it ?
– ilomax
Nov 10 at 17:00
@front_end_dev I added areturn
before everyres.send()
as you suggested and now the server crashes just by reloading the login page.
– ilomax
Nov 10 at 17:03
@ilomax does the query work as expected if you execute it directly in mysql interface?
– Berkays
Nov 10 at 17:43
|
show 1 more comment
There could be an escaping issue with the mail address. Can you try with"SELECT * FROM users WHERE email = " + mysql.escape(email)
instead
– Berkays
Nov 10 at 15:33
putreturn
keyword before res.send.return res.send("code":400, "failed":"error occurred");
– front_end_dev
Nov 10 at 15:44
@Berkays that solved the crash issue, but for some reasonresults
appears empty when logged (it wasn't previously). What could be the reason behind it ?
– ilomax
Nov 10 at 17:00
@front_end_dev I added areturn
before everyres.send()
as you suggested and now the server crashes just by reloading the login page.
– ilomax
Nov 10 at 17:03
@ilomax does the query work as expected if you execute it directly in mysql interface?
– Berkays
Nov 10 at 17:43
There could be an escaping issue with the mail address. Can you try with
"SELECT * FROM users WHERE email = " + mysql.escape(email)
instead– Berkays
Nov 10 at 15:33
There could be an escaping issue with the mail address. Can you try with
"SELECT * FROM users WHERE email = " + mysql.escape(email)
instead– Berkays
Nov 10 at 15:33
put
return
keyword before res.send. return res.send("code":400, "failed":"error occurred");
– front_end_dev
Nov 10 at 15:44
put
return
keyword before res.send. return res.send("code":400, "failed":"error occurred");
– front_end_dev
Nov 10 at 15:44
@Berkays that solved the crash issue, but for some reason
results
appears empty when logged (it wasn't previously). What could be the reason behind it ?– ilomax
Nov 10 at 17:00
@Berkays that solved the crash issue, but for some reason
results
appears empty when logged (it wasn't previously). What could be the reason behind it ?– ilomax
Nov 10 at 17:00
@front_end_dev I added a
return
before every res.send()
as you suggested and now the server crashes just by reloading the login page.– ilomax
Nov 10 at 17:03
@front_end_dev I added a
return
before every res.send()
as you suggested and now the server crashes just by reloading the login page.– ilomax
Nov 10 at 17:03
@ilomax does the query work as expected if you execute it directly in mysql interface?
– Berkays
Nov 10 at 17:43
@ilomax does the query work as expected if you execute it directly in mysql interface?
– Berkays
Nov 10 at 17:43
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
To log any exception in the code you need to put the code block inside try catch
try
// your code here
catch (error)
console.log(error);
res.send( code:400, failed: "error occurred");
please try this code and paste error here.
I've encapsulated the whole inside of mycon.query()
, from above theif (err)
statement down to after theres.send("code":204...)
in atry
. All I've got fromcatch
is a the exact same behaviour as previously described but the error is now only "Incorrect arguments", without thethrow err; // Rethrow non-MySQL errors ^
– ilomax
Nov 10 at 17:10
can you please post complete logs of results you are getting.
– Jawad Akram
Nov 10 at 22:24
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
To log any exception in the code you need to put the code block inside try catch
try
// your code here
catch (error)
console.log(error);
res.send( code:400, failed: "error occurred");
please try this code and paste error here.
I've encapsulated the whole inside of mycon.query()
, from above theif (err)
statement down to after theres.send("code":204...)
in atry
. All I've got fromcatch
is a the exact same behaviour as previously described but the error is now only "Incorrect arguments", without thethrow err; // Rethrow non-MySQL errors ^
– ilomax
Nov 10 at 17:10
can you please post complete logs of results you are getting.
– Jawad Akram
Nov 10 at 22:24
add a comment |
up vote
0
down vote
To log any exception in the code you need to put the code block inside try catch
try
// your code here
catch (error)
console.log(error);
res.send( code:400, failed: "error occurred");
please try this code and paste error here.
I've encapsulated the whole inside of mycon.query()
, from above theif (err)
statement down to after theres.send("code":204...)
in atry
. All I've got fromcatch
is a the exact same behaviour as previously described but the error is now only "Incorrect arguments", without thethrow err; // Rethrow non-MySQL errors ^
– ilomax
Nov 10 at 17:10
can you please post complete logs of results you are getting.
– Jawad Akram
Nov 10 at 22:24
add a comment |
up vote
0
down vote
up vote
0
down vote
To log any exception in the code you need to put the code block inside try catch
try
// your code here
catch (error)
console.log(error);
res.send( code:400, failed: "error occurred");
please try this code and paste error here.
To log any exception in the code you need to put the code block inside try catch
try
// your code here
catch (error)
console.log(error);
res.send( code:400, failed: "error occurred");
please try this code and paste error here.
answered Nov 10 at 15:43
Jawad Akram
12
12
I've encapsulated the whole inside of mycon.query()
, from above theif (err)
statement down to after theres.send("code":204...)
in atry
. All I've got fromcatch
is a the exact same behaviour as previously described but the error is now only "Incorrect arguments", without thethrow err; // Rethrow non-MySQL errors ^
– ilomax
Nov 10 at 17:10
can you please post complete logs of results you are getting.
– Jawad Akram
Nov 10 at 22:24
add a comment |
I've encapsulated the whole inside of mycon.query()
, from above theif (err)
statement down to after theres.send("code":204...)
in atry
. All I've got fromcatch
is a the exact same behaviour as previously described but the error is now only "Incorrect arguments", without thethrow err; // Rethrow non-MySQL errors ^
– ilomax
Nov 10 at 17:10
can you please post complete logs of results you are getting.
– Jawad Akram
Nov 10 at 22:24
I've encapsulated the whole inside of my
con.query()
, from above the if (err)
statement down to after the res.send("code":204...)
in a try
. All I've got from catch
is a the exact same behaviour as previously described but the error is now only "Incorrect arguments", without the throw err; // Rethrow non-MySQL errors ^
– ilomax
Nov 10 at 17:10
I've encapsulated the whole inside of my
con.query()
, from above the if (err)
statement down to after the res.send("code":204...)
in a try
. All I've got from catch
is a the exact same behaviour as previously described but the error is now only "Incorrect arguments", without the throw err; // Rethrow non-MySQL errors ^
– ilomax
Nov 10 at 17:10
can you please post complete logs of results you are getting.
– Jawad Akram
Nov 10 at 22:24
can you please post complete logs of results you are getting.
– Jawad Akram
Nov 10 at 22:24
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240391%2fnodejs-server-crashes-when-querying-mysql-database-with-incorrect-arguments-to%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There could be an escaping issue with the mail address. Can you try with
"SELECT * FROM users WHERE email = " + mysql.escape(email)
instead– Berkays
Nov 10 at 15:33
put
return
keyword before res.send.return res.send("code":400, "failed":"error occurred");
– front_end_dev
Nov 10 at 15:44
@Berkays that solved the crash issue, but for some reason
results
appears empty when logged (it wasn't previously). What could be the reason behind it ?– ilomax
Nov 10 at 17:00
@front_end_dev I added a
return
before everyres.send()
as you suggested and now the server crashes just by reloading the login page.– ilomax
Nov 10 at 17:03
@ilomax does the query work as expected if you execute it directly in mysql interface?
– Berkays
Nov 10 at 17:43