Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
collect and surface compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Oshry committed Sep 22, 2015
1 parent 08220a9 commit b065999
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
23 changes: 19 additions & 4 deletions lib/compiler/static-analysis/scjson-analyzer.js
Expand Up @@ -8,6 +8,7 @@ var systemVariables = ["_event", "_sessionid", "_name", "_ioprocessors", "_x"];
var scJsonAnalyzer = {
analyze: function(scJson, docUrl, context, done) {
var changes = [],
syntaxErrors = [],
asyncCount = 0,
waitingForAsync = false;

Expand Down Expand Up @@ -295,6 +296,16 @@ var scJsonAnalyzer = {
}

function handleError (node, property, errors, $type, state, override) {
if (errors && errors.length) {
var n = node[property];
syntaxErrors.push({
tagname: n.$type,
line: n.$line,
column: n.$column,
reason: errors.join('; ')
});
}

var errorNode = {
$line : node[property].$line,
$column : node[property].$column,
Expand Down Expand Up @@ -328,9 +339,8 @@ var scJsonAnalyzer = {
return JSON.stringify(str.replace(/^\s+|\s+$|\s+(?=\s)/g, '').replace(/\s/g, " "));
}

function commitChanges (scJson) {
function commitChanges (scJson, errors) {
changes.forEach(function (change) {

if(change.$type === 'data' && !change.new) {
delete scJson.datamodel;
scJson.onEntry = [ change.new || change.error ];
Expand Down Expand Up @@ -363,8 +373,13 @@ var scJsonAnalyzer = {
}

function completeAnalysis () {
commitChanges(scJson);
done({ scJson: scJson, errors: [] });
if (syntaxErrors.length) {
scJson = undefined;
} else {
commitChanges(scJson);
}

done({ scJson: scJson, errors: syntaxErrors });
}

processState(scJson, 'scJson');
Expand Down
11 changes: 2 additions & 9 deletions lib/runtime/document-string-to-model.js
Expand Up @@ -27,15 +27,8 @@ function documentStringToModel(url,docString,cb,context){

scJsonAnalyzer.analyze(scJson, url, context, function (result) {
if (result.errors.length) {
//Log errors

//TODO Value --force is set
if (true) {

} else {
//TODO Throw error and kill process

};
cb(result.errors);
return;
};

createModule(url, result.scJson, context, cb);
Expand Down

0 comments on commit b065999

Please sign in to comment.