Uncaught SyntaxError: BREAK statement outside of SWITCH, FOR or WHILE loop
(But it's not.)
On the left side:
Post
URL {
"method": "GET",
"host": "",
"path": "/CMD",
"pathname": "/CMD",
"search": null, "port": null, "query": null }
XXX /CMD
Length 67
pdata= {"name":"Btemp","a":0,"cmd":"pobj.a=E.getTemperature().toFixed(2)"}
pdata length= 67
{
"name": "Btemp",
"a": 0,
"cmd": "pobj.a=E.getTemperature().toFixed(2)"
}
Uncaught SyntaxError: BREAK statement outside of SWITCH, FOR or WHILE loop
at line 97 col 5
break;
^
Closed
>
The program continues running.
Part of the code on the right side
switch (a.pathname){
case "/CMD":
pobj=JSON.parse(pdata);
console.log(pobj);
if(pobj.cmd !==null){
eval(pobj.cmd);
pdata=JSON.stringify(pobj);
res.writeHead(200);
res.end(pdata);
}else{
res.writeHead(201);
res.end();
}//end if pobj.cmd
break; //this is the break being flaged on line 94
case "/LOGdata":
console.log("LOGdata= ",pdata);
res.writeHead(200); // this is the line reported 97
res.end(pdata);
break;
default:
res.writeHead(404);
res.end();
break;
}//end switch
pdata="";
}//end doPost1
Changing the code removes the error.
function doPost1(req,res){
var length;
var a = url.parse(req.url, true);
console.log("URL ",a);
console.log("XXX ",a.pathname);
length=req.headers["Content-Length"];
console.log("Length ",length);
console.log("pdata= ",pdata);
console.log("pdata length= ",pdata.length);
if(pdata.length!=length){
res.writeHead(404);
res.end();
pdata="";
return;
}//end if length
switch (a.pathname){
case "/CMD":
doCMD(req,res);
break;
case "/LOGdata":
console.log("LOGdata= ",pdata);
res.writeHead(200);
res.end(pdata);
break;
default:
res.writeHead(404);
res.end();
break;
}//end switch
pdata="";
}//end doPost1
function doCMD(req,res){
pobj=JSON.parse(pdata);
console.log(pobj);
if(pobj.cmd !==null){
eval(pobj.cmd);
pdata=JSON.stringify(pobj);
res.writeHead(200);
res.end(pdata);
}else{
res.writeHead(201);
res.end();
} //end if pobj.cmd
}//end doCMD
And on the left side:
Get/
Get/JPpostT9.html
html
End Pipe
Uncaught Error: Expecting a function to call, got Number
Post
URL {
"method": "GET",
"host": "",
"path": "/CMD",
"pathname": "/CMD",
"search": null, "port": null, "query": null }
XXX /CMD
Length 70
pdata= {"name":"LED1","a":0,"cmd":"pobj.a=!pobj.a;digitalWrite(LED1,pobj.a)"}
pdata length= 70
{
"name": "LED1",
"a": 0,
"cmd": "pobj.a=!pobj.a;digitalWrite(LED1,pobj.a)"
}
Closed
>
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Uncaught SyntaxError: BREAK statement outside of SWITCH, FOR or WHILE loop
(But it's not.)
On the left side:
The program continues running.
Part of the code on the right side
Changing the code removes the error.
And on the left side: