Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Aug 1, 2012
1 parent 4dba29e commit 02dcfb2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions demo/js/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ window.runDemo = function runDemo() {
});

function parse() {
var str;
var str, obj;

try {
str = source.getValue();
obj = jsyaml.load(str);

permalink.href = '#yaml=' + base64.encode(str);

result.setOption('mode', 'javascript');
result.setValue(inspect(jsyaml.load(str), false, 10));
result.setValue(inspect(obj, false, 10));
} catch (err) {
result.setOption('mode', 'text/plain');
result.setValue(err.toString());
result.setValue(err.stack || err.message || String(err));
}
}

Expand All @@ -38,7 +39,7 @@ window.runDemo = function runDemo() {
yaml = base64.decode(location.hash.slice(6));
}

source.setValue(yaml || fallback);
source.setValue(yaml || fallback || '');
parse();
}

Expand Down

0 comments on commit 02dcfb2

Please sign in to comment.