Skip to content

Commit

Permalink
Removed all try catch
Browse files Browse the repository at this point in the history
See #398.
  • Loading branch information
mcollina committed Apr 21, 2016
1 parent 3bf4378 commit da79b09
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 77 deletions.
37 changes: 9 additions & 28 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ var Nid = require('nid')
var Norma = require('norma')
var Errors = require('./errors')

var internals = {
error: Eraro({
package: 'seneca',
msgmap: Errors,
override: true
})
}

// Shortcuts
var arrayify = Function.prototype.apply.bind(Array.prototype.slice)

Expand All @@ -43,29 +35,18 @@ exports.die = function (msg) {
exports.parsePattern = function parse_pattern (instance, args, normaspec, fixed) {
args = Norma('{strargs:s? objargs:o? moreobjargs:o? ' + (normaspec || '') + '}', args)

try {
return _.extend(
args,
{ pattern: _.extend(
{},
return _.extend(
args,
{ pattern: _.extend(
{},

// Precedence of arguments in add,act is left-to-right
args.moreobjargs ? args.moreobjargs : {},
args.objargs ? args.objargs : {},
args.strargs ? Jsonic(args.strargs) : {},
// Precedence of arguments in add,act is left-to-right
args.moreobjargs ? args.moreobjargs : {},
args.objargs ? args.objargs : {},
args.strargs ? Jsonic(args.strargs) : {},

fixed || {})
})
}
catch (e) {
var col = (e.line === 1) ? e.column - 1 : e.column
throw internals.error('add_string_pattern_syntax', {
argstr: args,
syntax: e.message,
line: e.line,
col: col
fixed || {})
})
}
}

var copydata = exports.copydata = function (obj) {
Expand Down
24 changes: 4 additions & 20 deletions lib/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ function multiplexhandler (a, b) {
var fn = function () {
var args = arrayify(arguments)
_.each(multiplex, function (childfn) {
try {
if (typeof childfn === 'function') {
childfn.apply(null, args)
}
}
catch (e) {
console.error(e + args)
if (typeof childfn === 'function') {
childfn.apply(null, args)
}
})
}
Expand Down Expand Up @@ -434,22 +429,11 @@ exports.makelog = function (logspec, ctxt) {
if (handler) {
var lastval = args[args.length - 1]
if (_.isFunction(lastval)) {
var logvals = []
try {
logvals = lastval()
}
catch (e) {
logvals = [e, e.stack]
}
var logvals = lastval()
args = args.slice(0, args.length - 1).concat(logvals)
}

try {
handler.apply(null, args)
}
catch (e) {
console.error(e + args)
}
handler.apply(null, args)
}
}

Expand Down
8 changes: 1 addition & 7 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ module.exports.register = function (so, callpoint) {

seneca.log.debug('register', 'init', fullname, callpoint(), plugin_options)

try {
meta = define_plugin(delegate, plugin, plugin_options)
}
catch (e) {
// TODO: needs wrapping
return plugin_done(e)
}
meta = define_plugin(delegate, plugin, plugin_options)

// legacy api for service function
if (_.isFunction(meta)) {
Expand Down
25 changes: 3 additions & 22 deletions test/seneca.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,33 +813,13 @@ describe('seneca', function () {
next()
})
},
function (next) {
try {
si.add('a:,b:2', function (args, cb) {
cb()
})
}
catch (e) {
assert.equal(e.code, 'add_string_pattern_syntax')
next()
}
},
function (next) {
try {
si.act('a:,b:2', {c: 3}, function () {
assert.fail()
})
}
catch (e) {
assert.equal(e.code, 'add_string_pattern_syntax')
next()
}
},
function (next) {
try {
si.add('a:1,b:2', 'bad-arg', function (args, cb) {
cb()
})
assert.fail()
next()
}
catch (e) {
assert.ok(e.message.match(/norma:/))
Expand All @@ -849,6 +829,7 @@ describe('seneca', function () {
function (next) {
try {
si.add(123, function (args, cb) { cb() })
assert.fail()
}
catch (e) {
assert.ok(e.message.match(/norma:/))
Expand Down

0 comments on commit da79b09

Please sign in to comment.