Permalink
Browse files

Fix error reporting

  • Loading branch information...
Subbu Allamaraju
Subbu Allamaraju committed Feb 25, 2012
1 parent 81daec4 commit a91d1e6c9a74b8c5742b2758f5937526b68f9102
View
@@ -1,3 +1,7 @@
+## Feb 24, 2012
+
+* Escalte table/route loading errors to the logger
+
## Feb 22, 2012
* Export version from each module. You can find version of the engine using
View
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-app",
- "version": "0.4.2",
+ "version": "0.4.3",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
View
@@ -44,7 +44,6 @@ var Console = module.exports = function(config, cb) {
config = config || {};
- var engine = new Engine(config);
var logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({
@@ -53,27 +52,9 @@ var Console = module.exports = function(config, cb) {
})
]
});
- logger.setLevels(config['log levels'] || winston.config.syslog.levels);
-
- engine.setMaxListeners(25);
- engine.on(Engine.Events.EVENT, function(event, message) {
- if(message) {
- logger.info(new Date() + ' - ' + message);
- }
- });
- engine.on(Engine.Events.SCRIPT_DONE, function(event, message) {
- logger.info(new Date() + ' - ' + JSON.stringify(event));
- });
- engine.on(Engine.Events.ERROR, function(event, message) {
- if(message) {
- logger.error(new Date() + ' - ' + message.stack || message);
- }
- });
- engine.on(Engine.Events.WARNING, function(event, message) {
- if(message) {
- logger.warning(new Date() + ' - ' + message.stack || message);
- }
- });
+ logger.setLevels(config['log levels'] || winston.config.cli.levels);
+ config.logger = config.logger || logger;
+ var engine = new Engine(config);
if(config.tables) {
logger.info('Loading tables from ' + config.tables);
@@ -65,7 +65,32 @@ var Engine = module.exports = function(opts) {
opts = opts || {};
- // Load config
+ opts.logger = opts.logger || new (winston.Logger)();
+ // Attach listeners and loggers before doing anything
+ this.setMaxListeners(25);
+ this.on(Engine.Events.EVENT, function(event, message) {
+ if(message) {
+ opts.logger.info(new Date() + ' - ' + message);
+ }
+ });
+ this.on(Engine.Events.SCRIPT_DONE, function(event, message) {
+ opts.logger.info(new Date() + ' - ' + JSON.stringify(event));
+ });
+ this.on(Engine.Events.ERROR, function(event, message, err) {
+ if(message) {
+ opts.logger.error(new Date() + ' - ' + message);
+ }
+ if(err) {
+ opts.logger.error(err.stack || err);
+ }
+ });
+ this.on(Engine.Events.WARNING, function(event, message) {
+ if(message) {
+ opts.logger.warn(new Date() + ' - ' + message.stack || message);
+ }
+ });
+
+ // Load stuff
opts.config = opts.config || {};
this.config = _.isObject(opts.config) ? opts.config : configLoader.load({
config: opts.config,
@@ -382,10 +407,8 @@ function sweep(opts, parentEvent) {
state = opts.execState[last.id];
if(pending === 0 && state.waits > 0 && last.type === 'return') {
- return opts.cb({
- message: 'Script has unmet dependencies. The return statement depends on one/more other ' +
- 'statement(s), but those are not in-progress.'
- });
+ return opts.cb('Script has unmet dependencies. The return statement depends on one/more other ' +
+ 'statement(s), but those are not in-progress.');
}
if(pending == 0 && state.waits == 0) {
if(last.type === 'return') {
@@ -500,9 +523,7 @@ function _execOne(opts, statement, cb, parentEvent) {
else {
lhs = statement.rhs.ref ? opts.context[statement.rhs.ref] : statement.rhs.object;
if(_.isNull(lhs)) {
- cb({
- message: 'Unresolved reference in return'
- })
+ cb('Unresolved reference in return');
}
else {
var params = httpRequest.prepareParams(opts.context,
@@ -48,9 +48,7 @@ var arr = [], routes = opts.routes, context = opts.context, record, otherVerbs =
record = routes.simpleMap[statement.method + ':' + statement.path.value];
if(!record) {
- cb({
- message: 'No such route ' + statement.path.value + ' for HTTP method "' + 'statement.method"'
- });
+ cb('No such route ' + statement.path.value + ' for HTTP method "' + 'statement.method"');
}
cb(null, {
@@ -83,9 +83,7 @@ exports.exec = function(opts, statement, cb) {
});
}
else {
- cb({
- message: 'No such table ' + statement.source.name
- });
+ cb('No such table ' + statement.source.name);
}
}
@@ -60,14 +60,10 @@ exports.exec = function(opts, statement, cb, parentEvent) {
// Get the resource
table = opts.tempResources[name] || tables[name];
if(!table) {
- return insertTx.cb({
- message: 'No such resource ' + name
- });
+ return insertTx.cb('No such table ' + name);
}
if(!table.insert) {
- return insertTx.cb({
- message: 'Table ' + statement.source.name + ' does not support insert'
- });
+ return insertTx.cb('Table ' + statement.source.name + ' does not support insert');
}
httpRequest.exec({
@@ -74,7 +74,7 @@ function loadInternal(path, prefix, logEmitter, config, tables) {
if(err) {
logEmitter.emitError(err);
} else {
- assert.ok(table, 'resource should not be null');
+ assert.ok(table, 'table should not be null');
tables[table.name] = table;
}
}
@@ -76,6 +76,7 @@ var LogEmitter = module.exports = function() {
cb: function(e, r) {
var message = 'Success';
if (e) {
+ // TODO: This causes duplicate error events due to unwrapping ...
that.emit(eventTypes.ERROR, event, e);
message = 'Failure'
}
@@ -103,15 +104,19 @@ var LogEmitter = module.exports = function() {
}
this.emitError = function () {
- var event = {}, msg = 'Error event raised without message';
+ var event = {}, msg = 'Error event raised without message', cause;
if (arguments.length > 1) {
event = arguments[0];
msg = arguments[1];
+ if(msg.stack) {
+ cause = msg;
+ msg = msg.message;
+ }
}
else if (arguments.length === 1) {
msg = arguments[0];
}
- this.emit(eventTypes.ERROR, event, msg);
+ this.emit(eventTypes.ERROR, event, msg, cause);
}
function getUTimeInSecs() {
@@ -1,12 +1,12 @@
{
"author": "ql.io",
"name": "ql.io-engine",
- "version": "0.4.7",
+ "version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
},
- "engines": {
+ "engine": {
"node":"> 0.6.0"
},
"main": "lib/engine.js",

0 comments on commit a91d1e6

Please sign in to comment.