Skip to content

Commit

Permalink
#382 - graceful error handling for unexpected or unhandled errors (#383)
Browse files Browse the repository at this point in the history
Sending a PR to handle previously unhandled errors that are outside of missing UI elements, error-handling during step and integrations execution, unrecognizable steps, missing parameters etc.

An example would be referencing a variable that is not yet declared -
```
ReferenceError: Can't find variable: abc
  /Users/kensoh/Cloud Drive/Marketing/Website/api/tagui/src/phantomjs:/code/demo.js:1386
  /Users/kensoh/Cloud Drive/Marketing/Website/api/tagui/src/phantomjs:/platform/casper.js:1685 in runStep
  /Users/kensoh/Cloud Drive/Marketing/Website/api/tagui/src/phantomjs:/platform/casper.js:414 in checkStep
```

---

With this PR, the following standard error message from TagUI will be displayed instead -
```
ERROR - can't find variable: b
```
  • Loading branch information
kensoh authored Apr 7, 2019
1 parent da279b1 commit ed7f46a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/tagui_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ else return call_sikuli(raw_intent,params);}

function mouse_intent(raw_intent) {raw_intent = eval("'" + escape_bs(raw_intent) + "'"); // support dynamic variables
var params = ((raw_intent + ' ').substr(1+(raw_intent + ' ').indexOf(' '))).trim();
if (params == '') return "this.echo('ERROR - up / down missing for " + raw_intent + "')";
if (params == '') return "this.echo('ERROR - down / up missing for " + raw_intent + "')";
else if (params.toLowerCase() == 'down') return call_sikuli(raw_intent,'down');
else if (params.toLowerCase() == 'up') return call_sikuli(raw_intent,'up');
else return "this.echo('ERROR - cannot understand step " + raw_intent + "')";}
Expand Down Expand Up @@ -1343,3 +1343,8 @@ function getTimeoutAndCheckNextStepFunction(timeout, then, methodName, defaultTi
return timeout;
}

// global try-catch for catching unexpected and unhandled errors, eg referencing an undeclared variable
phantom.onError = function(msg, trace) {if (msg.indexOf('Error:') !== -1) { // clean up and format error message
msg = msg.substring(msg.indexOf('Error:')+6).trim(); msg = msg.charAt(0).toLowerCase() + msg.slice(1);}
casper.echo('ERROR - ' + msg).exit();}

2 changes: 1 addition & 1 deletion src/tagui_parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ function keyboard_intent($raw_intent) {

function mouse_intent($raw_intent) {
$params = trim(substr($raw_intent." ",1+strpos($raw_intent." "," ")));
if ($params == "") echo "ERROR - " . current_line() . " up / down missing for " . $raw_intent . "\n";
if ($params == "") echo "ERROR - " . current_line() . " down / up missing for " . $raw_intent . "\n";
else if (strtolower($params) == "down") return "casper.then(function() {".call_sikuli($raw_intent,"down");
else if (strtolower($params) == "up") return "casper.then(function() {".call_sikuli($raw_intent,"up");
else echo "ERROR - " . current_line() . " cannot understand step " . $raw_intent . "\n";}
Expand Down
7 changes: 6 additions & 1 deletion src/test/positive_test.signature
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ else return call_sikuli(raw_intent,params);}

function mouse_intent(raw_intent) {raw_intent = eval("'" + escape_bs(raw_intent) + "'"); // support dynamic variables
var params = ((raw_intent + ' ').substr(1+(raw_intent + ' ').indexOf(' '))).trim();
if (params == '') return "this.echo('ERROR - up / down missing for " + raw_intent + "')";
if (params == '') return "this.echo('ERROR - down / up missing for " + raw_intent + "')";
else if (params.toLowerCase() == 'down') return call_sikuli(raw_intent,'down');
else if (params.toLowerCase() == 'up') return call_sikuli(raw_intent,'up');
else return "this.echo('ERROR - cannot understand step " + raw_intent + "')";}
Expand Down Expand Up @@ -1370,6 +1370,11 @@ function getTimeoutAndCheckNextStepFunction(timeout, then, methodName, defaultTi
return timeout;
}

// global try-catch for catching unexpected and unhandled errors, eg referencing an undeclared variable
phantom.onError = function(msg, trace) {if (msg.indexOf('Error:') !== -1) { // clean up and format error message
msg = msg.substring(msg.indexOf('Error:')+6).trim(); msg = msg.charAt(0).toLowerCase() + msg.slice(1);}
casper.echo('ERROR - ' + msg).exit();}

// flow path for save_text and snap_image
var flow_path = '/full_path';

Expand Down

0 comments on commit ed7f46a

Please sign in to comment.