Skip to content

Commit

Permalink
modules to skip and everything else is now configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
AriaMinaei committed Jan 23, 2014
1 parent d554e0b commit 31aa4e7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 23 deletions.
42 changes: 35 additions & 7 deletions scripts/coffee/lib/ParsedError.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ module.exports = class ParsedError

addr = text.trim()

addr = @_fixPath addr

remaining = addr

# remove the <js> clause if the file is a compiled one
Expand Down Expand Up @@ -188,9 +190,13 @@ module.exports = class ParsedError

if dir is '.' then dir = ''

path = @_fixPath path
file = @_fixPath file
dir = @_fixPath dir

if dir?

d = dir.replace ///\\///g, '/'
d = dir.replace /[\\]{1,2}/g, '/'

if m = d.match ///
node_modules/([^/]+)(?!.*node_modules.*)
Expand All @@ -205,10 +211,14 @@ module.exports = class ParsedError

if path?

shortenedPath = @_shortenPath path
r = @_rectifyPath path

shortenedPath = r.path

shortenedAddr = shortenedPath + addr.substr(path.length, addr.length)

modules = r.modules

{

original: original
Expand All @@ -224,6 +234,7 @@ module.exports = class ParsedError
modName: modName
shortenedPath: shortenedPath
shortenedAddr: shortenedAddr
modules: modules || []

}

Expand Down Expand Up @@ -255,43 +266,60 @@ module.exports = class ParsedError

@_trace

_shortenPath: (path, nameForCurrentPackage) ->
_fixPath: (path) ->

path = String path
path.replace(///[\\]{1,2}///g, '/')

_rectifyPath: (path, nameForCurrentPackage) ->

path = path.replace('\\\\', '/').replace('\\', '/')
path = String path

remaining = path

return path unless m = path.match /^(.+?)\/node_modules\/(.+)$/
unless m = path.match /^(.+?)\/node_modules\/(.+)$/

return {path: path, modules: []}

parts = []

modules = []

if typeof nameForCurrentPackage is 'string'

parts.push "[#{nameForCurrentPackage}]"

modules.push "[#{nameForCurrentPackage}]"

else

parts.push "[#{m[1].match(/([^\/]+)$/)[1]}]"

modules.push m[1].match(/([^\/]+)$/)[1]

rest = m[2]

while m = rest.match /([^\/]+)\/node_modules\/(.+)$/

parts.push "[#{m[1]}]"

modules.push m[1]

rest = m[2]

if m = rest.match /([^\/]+)\/(.+)$/

parts.push "[#{m[1]}]"

modules.push m[1]

rest = m[2]

parts.push rest

parts.join "/"
{
path: parts.join "/"
modules: modules
}



Expand Down
78 changes: 62 additions & 16 deletions scripts/coffee/lib/PrettyError.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,46 @@ module.exports = class PrettyError

constructor: ->

@_maxItems = 50

@_modulesToSkip = []

@_pathsToSkip = []

@_skipCallbacks = []

@_renderer = new RenderKid

@_style = self._getDefaultStyle()

@_renderer.style @_style

skipModule: (modName) ->

@_modulesToSkip.push String modName

@

skipPath: (fileName) ->

@_pathsToSkip.push fileName

@

skip: (cb) ->

@_skipCallbacks.push cb

@

setMaxItems: (maxItems = 50) ->

if maxItems is 0 then maxItems = 1000

@_maxItems = maxItems|0

@

_getStyle: ->

@_style
Expand All @@ -35,9 +69,9 @@ module.exports = class PrettyError

@_renderer

render: (e, logIt = no, skipModules = no, maxTraceItems) ->
render: (e, logIt = no) ->

obj = @getObject e, skipModules, maxTraceItems
obj = @getObject e

rendered = @_renderer.render(obj)

Expand All @@ -47,23 +81,38 @@ module.exports = class PrettyError

rendered

getObject: (e, skipModules = no, maxTraceItems = 50) ->
_skipOrFilter: (item, itemNumber) ->

unless e instanceof ParsedError
if typeof item is 'object'

e = new ParsedError e
return yes if item.modName in @_modulesToSkip

return yes if item.path in @_pathsToSkip

for modName in item.modules

return yes if modName in @_modulesToSkip

for cb in @_skipCallbacks

return yes if cb(item, itemNumber) is yes

return no

getObject: (e) ->

unless typeof skipModules is 'boolean' or Array.isArray skipModules
unless e instanceof ParsedError

throw Error "skipModules only accepts a boolean or an array of module names"
e = new ParsedError e

header =

title: do ->

ret = {}


# some errors are thrown to display other errors.
# we call them wrappers here.
if e.wrapper isnt ''

ret.wrapper = e.wrapper + ":"
Expand All @@ -72,7 +121,6 @@ module.exports = class PrettyError

ret


colon: ':'

message: e.message
Expand All @@ -85,9 +133,13 @@ module.exports = class PrettyError

continue unless item?

if @_skipOrFilter(item, i) is yes

continue

count++

break if count > maxTraceItems
break if count > @_maxItems

if typeof item is 'string'

Expand All @@ -97,12 +149,6 @@ module.exports = class PrettyError

continue

if skipModules isnt no and i > 0

continue if skipModules is yes and item.modName is '[current]'

continue if item.modName in skipModules

traceItems.push item:

header:
Expand Down

0 comments on commit 31aa4e7

Please sign in to comment.