Skip to content

Commit

Permalink
fix(names): fix anonymous plugins, fallback
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
tunnckoCore committed Oct 27, 2016
1 parent ec2d90e commit 0a506b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ utils.delegate(MiniBase.prototype, {
// hide them
this.define('_events', this._events)
this.define('_eventsCount', this._eventsCount)
this.define('_anonymousPluginsCount', 1)

// default error handlers
this.once('error', this.options.silent === true
Expand Down Expand Up @@ -239,8 +240,9 @@ utils.delegate(MiniBase.prototype, {
fn = fn.bind(this, this)
utils.tryCatch(fn, (err, res) => {
if (err) {
var anon = 'anonymous ' + (this._anonymousPluginsCount + 1)
err.fn = fn
err.fnName = utils.getFnName(fn)
err.fnName = utils.getFnName(fn) || anon
this.emit('error', err)
return
}
Expand Down
4 changes: 3 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ let app = new MiniBase({
// uncomment to handle the errors,
// even if `silent: true`
//
// app.once('error', console.log)
app.once('error', function (err) {
console.log(err.fnName) // => anonymous 1
})

app.use(function (ctx) {
console.log(ctx)
Expand Down

0 comments on commit 0a506b7

Please sign in to comment.