NodeJS server crashes when querying MySQL database with “Incorrect arguments” to throw error










0















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 '18 at 15:33












  • put return keyword before res.send. return res.send("code":400, "failed":"error occurred");

    – front_end_dev
    Nov 10 '18 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 '18 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 '18 at 17:03











  • @ilomax does the query work as expected if you execute it directly in mysql interface?

    – Berkays
    Nov 10 '18 at 17:43















0















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 '18 at 15:33












  • put return keyword before res.send. return res.send("code":400, "failed":"error occurred");

    – front_end_dev
    Nov 10 '18 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 '18 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 '18 at 17:03











  • @ilomax does the query work as expected if you execute it directly in mysql interface?

    – Berkays
    Nov 10 '18 at 17:43













0












0








0








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 '18 at 18:30







ilomax

















asked Nov 10 '18 at 15:24









ilomaxilomax

148214




148214












  • 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 '18 at 15:33












  • put return keyword before res.send. return res.send("code":400, "failed":"error occurred");

    – front_end_dev
    Nov 10 '18 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 '18 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 '18 at 17:03











  • @ilomax does the query work as expected if you execute it directly in mysql interface?

    – Berkays
    Nov 10 '18 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 '18 at 15:33












  • put return keyword before res.send. return res.send("code":400, "failed":"error occurred");

    – front_end_dev
    Nov 10 '18 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 '18 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 '18 at 17:03











  • @ilomax does the query work as expected if you execute it directly in mysql interface?

    – Berkays
    Nov 10 '18 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 '18 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 '18 at 15:33














put return keyword before res.send. return res.send("code":400, "failed":"error occurred");

– front_end_dev
Nov 10 '18 at 15:44





put return keyword before res.send. return res.send("code":400, "failed":"error occurred");

– front_end_dev
Nov 10 '18 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 '18 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 '18 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 '18 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 '18 at 17:03













@ilomax does the query work as expected if you execute it directly in mysql interface?

– Berkays
Nov 10 '18 at 17:43





@ilomax does the query work as expected if you execute it directly in mysql interface?

– Berkays
Nov 10 '18 at 17:43












1 Answer
1






active

oldest

votes


















0














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 '18 at 17:10












  • can you please post complete logs of results you are getting.

    – Jawad Akram
    Nov 10 '18 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',
autoActivateHeartbeat: false,
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









0














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 '18 at 17:10












  • can you please post complete logs of results you are getting.

    – Jawad Akram
    Nov 10 '18 at 22:24















0














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 '18 at 17:10












  • can you please post complete logs of results you are getting.

    – Jawad Akram
    Nov 10 '18 at 22:24













0












0








0







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 '18 at 15:43









Jawad AkramJawad 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 '18 at 17:10












  • can you please post complete logs of results you are getting.

    – Jawad Akram
    Nov 10 '18 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 '18 at 17:10












  • can you please post complete logs of results you are getting.

    – Jawad Akram
    Nov 10 '18 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 '18 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 '18 at 17:10














can you please post complete logs of results you are getting.

– Jawad Akram
Nov 10 '18 at 22:24





can you please post complete logs of results you are getting.

– Jawad Akram
Nov 10 '18 at 22:24

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




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







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages