Skip to content

Commit

Permalink
Throw error when subclass name is not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
dasilvacontin committed Aug 25, 2015
1 parent d96d9c2 commit ca070f3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions subclass-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
var ErrorInheritor = function () {}
function SubclassError (name, BaseError, props) {
if (name === undefined) throw new Error('Name of subclass must be provided as first argument.')
if (typeof name !== 'string') throw new Error('Expected first argument to be a string in SubclassError(name, [BaseError, [props]])')
if (!(BaseError instanceof Function)) {
props = BaseError
BaseError = Error
Expand All @@ -27,11 +28,11 @@
// stack "hack"
var sample = (new Error())
if (!sample.stack) sample.stack = ''
var goodStack = sample.stack.split('\n')
goodStack.splice(1, 1)
goodStack[0] = name
if (message) goodStack[0] += ': ' + message
this.stack = goodStack.join('\n')
var niceStack = sample.stack.split('\n')
niceStack.splice(1, 1)
niceStack[0] = name
if (message) niceStack[0] += ': ' + message
this.stack = niceStack.join('\n')
}
e.prototype = new ErrorInheritor()
e.prototype.constructor = e
Expand Down

0 comments on commit ca070f3

Please sign in to comment.