Skip to content

Commit

Permalink
Fixes beeware#375 -- Display python exceptions on stderr.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Nov 13, 2016
1 parent 43acb1d commit 59093f7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions batavia/VirtualMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ batavia.VirtualMachine.prototype.run = function(tag, args) {

} catch (e) {
if (e instanceof batavia.builtins.BataviaError) {
console.log(e.msg);
batavia.stderr(e.msg);
} else {
throw e;
}
Expand Down Expand Up @@ -532,7 +532,7 @@ batavia.VirtualMachine.prototype.run_method = function(tag, args, kwargs, f_loca

} catch (e) {
if (e instanceof batavia.builtins.BataviaError) {
console.log(e.msg);
batavia.stderr(e.msg);
} else {
throw e;
}
Expand Down Expand Up @@ -832,7 +832,7 @@ batavia.VirtualMachine.prototype.run_code = function(kwargs) {
} else {
trace.push(this.last_exception.value.name);
}
console.log(trace.join('\n'));
batavia.stderr(trace.join('\n'));
this.last_exception = null;
} else {
throw e;
Expand Down
5 changes: 5 additions & 0 deletions testserver/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ h3 {
background-color: #fff;
}

#stdout span.error {
font-weight: bold;
color: #b00;
}

p, button {
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
}
Expand Down
11 changes: 10 additions & 1 deletion testserver/testbed.html
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,22 @@
console.log('done.');
}

// Now define a stdout function that will output to the page.
// Now define stdout and stderr functions that will output to the page.
function stdout(content) {
var pre = document.getElementById('stdout');
pre.textContent = pre.textContent + content;
}

batavia.stdout = stdout;

function stdout(content) {
var pre = document.getElementById('stdout');
var err = document.createElement('span');
err.className = "error";
err.textContent = content
pre.appendChild(err);
}

batavia.stderr = stdout;
</script>

Expand Down

0 comments on commit 59093f7

Please sign in to comment.