diff --git a/lib/api.js b/lib/api.js index 001e6143..01bbab67 100644 --- a/lib/api.js +++ b/lib/api.js @@ -275,7 +275,7 @@ exports.sub = function() { var self = this //var private$ = self.private$ var private_sub = self.private$.sub - + var subargs = Common.parsePattern(self, arguments, 'action:f actdef:o?') var pattern = subargs.pattern if ( @@ -301,13 +301,23 @@ exports.sub = function() { if (subfuncs) { meta.sub = subfuncs.pattern var actdef = subfuncs.actdef - + _.each(subfuncs, function subfunc(subfunc) { try { - for( var stI = 0, stlen = private_sub.tracers.length; - stI < stlen; stI++ ) { + for ( + var stI = 0, stlen = private_sub.tracers.length; + stI < stlen; + stI++ + ) { //private_sub.tracers[stI].call(self, self, msg, result, meta, actdef) - private_sub.tracers[stI].call(self, subfunc.instance$, msg, result, meta, actdef) + private_sub.tracers[stI].call( + self, + subfunc.instance$, + msg, + result, + meta, + actdef + ) } //subfunc.call(self, msg, result, meta) @@ -356,7 +366,7 @@ exports.sub = function() { } subs.push(subargs.action) subargs.action.instance$ = self - + return self } diff --git a/lib/outward.js b/lib/outward.js index 8b0fe765..9ee42bcb 100644 --- a/lib/outward.js +++ b/lib/outward.js @@ -87,10 +87,10 @@ function outward_res_object(ctxt, data) { var msg = data.msg var res = data.res - if( void 0 === data.res ) { + if (void 0 === data.res) { data.res = null } - + var not_object = res != null && !( @@ -110,20 +110,18 @@ function outward_res_object(ctxt, data) { ) if (so.strict.result && not_legacy && not_object) { - //data.res = outward.error || error(outward.code, outward.info) data.res = ctxt.seneca.private$.error('result_not_objarr', { - pattern: ctxt.actdef.pattern, - args: Util.inspect(Common.clean(msg)).replace(/\n/g, ''), - result: res + pattern: ctxt.actdef.pattern, + args: Util.inspect(Common.clean(msg)).replace(/\n/g, ''), + result: res }) - data.meta.error = true + data.meta.error = true } } - function outward_announce(ctxt, data) { - if(!ctxt.actdef) return + if (!ctxt.actdef) return if (_.isFunction(ctxt.seneca.on_act_out)) { ctxt.seneca.on_act_out(ctxt.actdef, data.res, data.meta) @@ -141,10 +139,9 @@ function outward_announce(ctxt, data) { ) } - function outward_trace(ctxt, data) { var private$ = ctxt.seneca.private$ - + var meta = data.meta var reply_meta = data.reply_meta @@ -166,7 +163,6 @@ function outward_trace(ctxt, data) { } } - function outward_act_error(ctxt, data) { var delegate = ctxt.seneca var actdef = ctxt.actdef @@ -207,15 +203,13 @@ function outward_act_error(ctxt, data) { delete data.err.meta$ data.res = null - + data.meta = data.error_desc.err.meta$ || data.meta - } - else { + } else { data.err = null } } - function outward_res_entity(ctxt, data) { var delegate = ctxt.seneca if (data.res && data.res.entity$ && delegate.make$) { diff --git a/seneca.js b/seneca.js index 844478db..5cdea200 100644 --- a/seneca.js +++ b/seneca.js @@ -512,7 +512,6 @@ function make_seneca(initial_options) { .add(Outward.announce) .add(Outward.act_error) - if (opts.$.test) { root$.test('string' === typeof opts.$.test ? opts.$.test : 'print') } @@ -1288,8 +1287,6 @@ intern.handle_reply = function(meta, actctxt, actmsg, err, out, reply_meta) { meta.end = Date.now() var delegate = actctxt.seneca - var actdef = actctxt.actdef - var origmsg = actctxt.origmsg var reply = actctxt.reply var data = { @@ -1305,29 +1302,16 @@ intern.handle_reply = function(meta, actctxt, actmsg, err, out, reply_meta) { actctxt.duration = meta.end - meta.start actctxt.actlog = actlog actctxt.act_error = intern.act_error - + meta.error = data.res instanceof Error intern.process_outward(actctxt, data) - + if (data.has_callback) { try { reply.call(delegate, data.err, data.res, data.meta) - } catch (e) { - var ex = Util.isError(e) ? e : new Error(Util.inspect(e)) - - intern.callback_error( - delegate, - ex, - actdef, - meta, - [err, out], - reply, - actctxt.duration, - actmsg, - origmsg, - actctxt.callpoint - ) + } catch (thrown_obj) { + intern.callback_error(delegate, thrown_obj, actctxt, data) } } } @@ -1564,21 +1548,21 @@ intern.act_error = function( } } -intern.callback_error = function( - instance, - err, - actdef, - meta, - result, - cb, - duration, - msg, - origmsg, - act_callpoint -) { - var opts = instance.options() +intern.callback_error = function(instance, thrown_obj, actctxt, data) { + var duration = actctxt.duration + var act_callpoint = actctxt.callpoint + var actdef = actctxt.actdef || {} + var origmsg = actctxt.origmsg + var reply = actctxt.reply - actdef = actdef || {} + var meta = data.meta + var msg = data.msg + + var err = Util.isError(thrown_obj) + ? thrown_obj + : new Error(Util.inspect(thrown_obj)) + + var opts = instance.options() if (!err.seneca) { err = error( @@ -1588,13 +1572,11 @@ intern.callback_error = function( message: err.message, pattern: actdef.pattern, fn: actdef.func, - cb: cb, + callback: reply, instance: instance.toString(), callpoint: act_callpoint }) ) - - result[0] = err } err.details = err.details || {} @@ -1612,7 +1594,7 @@ intern.callback_error = function( }) ) - instance.emit('act-err', msg, err, result[1]) + instance.emit('act-err', msg, err, data.res) if (opts.errhandler) { opts.errhandler.call(instance, err, err.meta$) diff --git a/test/seneca.test.js b/test/seneca.test.js index e0cd8b03..f96bbc02 100644 --- a/test/seneca.test.js +++ b/test/seneca.test.js @@ -1132,7 +1132,7 @@ describe('seneca', function() { }) it('strict-result', function(fin) { - var si = Seneca({ log: 'silent', legacy: {transport: false} }) + var si = Seneca({ log: 'silent', legacy: { transport: false } }) si .add('a:1', function(msg, reply) { @@ -1383,7 +1383,7 @@ describe('seneca', function() { .ready(done) }) - it('memory', function(done) { + it('memory', { timeout: 2222 * tmx }, function(done) { var SIZE = 1000 Seneca({ log: 'silent' }) @@ -1406,7 +1406,7 @@ describe('seneca', function() { function validate(start) { var end = Date.now() - expect(end - start).below(1500*tmx) + expect(end - start).below(1500 * tmx) var mem = process.memoryUsage() expect(mem.rss).below(200000000) @@ -1490,58 +1490,48 @@ describe('seneca', function() { .ready(fin) }) - it('pattern-types', function(fin) { Seneca() .test(fin) + // Just the value types from json.org, excluding object and array - // Just the value types from json.org, excluding object and array - - .add({s:'s'}, function(msg, reply) { - reply({s: msg.s}) + .add({ s: 's' }, function(msg, reply) { + reply({ s: msg.s }) }) - - .add({i:1}, function(msg, reply) { - reply({i: msg.i}) + .add({ i: 1 }, function(msg, reply) { + reply({ i: msg.i }) }) - - .add({f:1.1}, function(msg, reply) { - reply({f: msg.f}) + .add({ f: 1.1 }, function(msg, reply) { + reply({ f: msg.f }) }) - - .add({bt:true}, function(msg, reply) { - reply({bt: msg.bt}) + .add({ bt: true }, function(msg, reply) { + reply({ bt: msg.bt }) }) - - .add({bf:false}, function(msg, reply) { - reply({bf: msg.bf}) + .add({ bf: false }, function(msg, reply) { + reply({ bf: msg.bf }) }) - - .add({n:null}, function(msg, reply) { - reply({n: msg.n}) + .add({ n: null }, function(msg, reply) { + reply({ n: msg.n }) }) - .gate() - - .act({s:'s'}, function(ignore, out) { + .act({ s: 's' }, function(ignore, out) { expect(Util.inspect(out)).equal("{ s: 's' }") }) - .act({i:1}, function(ignore, out) { - expect(Util.inspect(out)).equal("{ i: 1 }") + .act({ i: 1 }, function(ignore, out) { + expect(Util.inspect(out)).equal('{ i: 1 }') }) - .act({f:1.1}, function(ignore, out) { - expect(Util.inspect(out)).equal("{ f: 1.1 }") + .act({ f: 1.1 }, function(ignore, out) { + expect(Util.inspect(out)).equal('{ f: 1.1 }') }) - .act({bt:true}, function(ignore, out) { - expect(Util.inspect(out)).equal("{ bt: true }") + .act({ bt: true }, function(ignore, out) { + expect(Util.inspect(out)).equal('{ bt: true }') }) - .act({bf:false}, function(ignore, out) { - expect(Util.inspect(out)).equal("{ bf: false }") + .act({ bf: false }, function(ignore, out) { + expect(Util.inspect(out)).equal('{ bf: false }') }) - .act({n:null}, function(ignore, out) { - expect(Util.inspect(out)).equal("{ n: null }") + .act({ n: null }, function(ignore, out) { + expect(Util.inspect(out)).equal('{ n: null }') }) .ready(fin) }) - })