basic error handling.

This commit is contained in:
Danny Yoo 2013-03-05 16:54:05 -07:00
parent 48b1ca271d
commit 3da2292247

View File

@ -1,5 +1,6 @@
$(document).ready(function() { $(document).ready(function() {
"use strict"; "use strict";
if (! console.log) { console.log = function() { }; }
var repl = $("#repl"); var repl = $("#repl");
var output = $("#output"); var output = $("#output");
@ -16,7 +17,7 @@ $(document).ready(function() {
$(domNode).appendTo(output); $(domNode).appendTo(output);
} }
M.params.currentErrorDisplayer = function(MACHINE, domNode) { M.params.currentErrorDisplayer = function(MACHINE, domNode) {
$(domNode).appendTo(output); $(domNode).css("color", "red").appendTo(output);
} }
@ -29,7 +30,6 @@ $(document).ready(function() {
M, M,
function() { function() {
M.params.currentNamespace = semanticsModule.getNamespace(); M.params.currentNamespace = semanticsModule.getNamespace();
console.log("Environment initialized.");
afterLanguageInitialization(); afterLanguageInitialization();
}, },
function(M, err) { function(M, err) {
@ -37,7 +37,7 @@ $(document).ready(function() {
console.log(M); console.log(M);
console.log(err); console.log(err);
console.log(err.stack); console.log(err.stack);
alert("uh oh!"); alert("uh oh!: language could not be loaded.");
}); });
}; };
repl.attr('disabled', 'true'); repl.attr('disabled', 'true');
@ -54,7 +54,7 @@ $(document).ready(function() {
repl.attr('disabled', 'true'); repl.attr('disabled', 'true');
repl.val("... evaluating..."); repl.val("... evaluating...");
breakButton.show(); breakButton.show();
evaluate(src, compileAndEvaluate(src,
function() { repl.removeAttr('disabled'); function() { repl.removeAttr('disabled');
repl.val(""); repl.val("");
breakButton.hide();}); breakButton.hide();});
@ -99,8 +99,7 @@ $(document).ready(function() {
// In evaluation, we'll send compilation requests to the server, // In evaluation, we'll send compilation requests to the server,
// and get back bytecode that we should evaluate. // and get back bytecode that we should evaluate.
var evaluate = function(src, after) { var compileAndEvaluate = function(src, after) {
console.log("about to eval", src);
$("<tt/>").text('> ' + src).appendTo(output); $("<tt/>").text('> ' + src).appendTo(output);
$("<br/>").appendTo(output); $("<br/>").appendTo(output);
var onCompile = function(compiledResult) { var onCompile = function(compiledResult) {
@ -120,18 +119,25 @@ $(document).ready(function() {
k(); k();
}; };
var onBadEvaluation = function(M, err) { var onBadEvaluation = function(M, err) {
console.log('bad evaluation');
console.log(err); console.log(err);
if (err.stack) { if (err.stack) {
console.log(err.stack); console.log(err.stack);
} }
if (err.message) {
$("<span/>")
.text(err.message)
.css("color", "red")
.appendTo(output);
$("<br/>").appendTo(output);
}
after(); after();
}; };
codeFunction(M, onGoodEvaluation, onBadEvaluation); codeFunction(M, onGoodEvaluation, onBadEvaluation);
}, },
after); after);
}; };
var onError = function(err) { var onServerError = function(err) {
console.log("error", err); console.log("error", err);
after(); after();
}; };
@ -140,7 +146,7 @@ $(document).ready(function() {
url: '/compile', url: '/compile',
data: { src: src }, data: { src: src },
success: onCompile, success: onCompile,
error: onError}); error: onServerError});
}; };