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.










share|improve this question























  • 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 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














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.










share|improve this question























  • 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 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












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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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











  • 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 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
















  • 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 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















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












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.






share|improve this answer




















  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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.






share|improve this answer




















  • 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














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.






share|improve this answer




















  • 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












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 15:43









Jawad Akram

12




12











  • 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
















  • 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















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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3