AriaMinaei / pretty-error

See node.js errors with less clutter
MIT License
1.52k stars 48 forks source link

Question: How do I format parsed error? #23

Closed reggi closed 9 years ago

reggi commented 9 years ago

I create a module called evalmd that evaluates markdown files. Ideally I'd only want to show the trace of the markdown file. I don't expect this to be a feature of pretty-error, but I'd like to skip stack trace lines by extension. How after I edit a trace could I assemble the error again? I can't seem to overwrite the parsedError.trace variable and throw parsedError. @AriaMinaei thoughts?

var ParsedError = require('pretty-error/lib/parsed-error')
var _ = require('lodash')
var parsedError = new ParsedError(err)
var newTrace = _.filter(parsedError.trace, function (line) {
  var validExt = ['.md', '.markdown']
  var lineExt = path.extname(line.file)
  var isMarkdown = _.contains(validExt, lineExt)
  return isMarkdown
})

I'm I stuck having to stitch all the pieces together by hand? Or does pretty-error have a way to do this?

Ideally I could:

  1. set the value of properties parsedError.setTrace(trace)
  2. convert parsedError back to a error parsedError.toError()
reggi commented 9 years ago

I suppose I can use pretty-error and skip via callback. But don't know how to have default default style.

reggi commented 9 years ago

Trying to create a "default-default" template. Could use help :cake:

var nullStyle = {
  background: 'none',
  display: 'inline',
  color: 'none',
  bullet: 'none',
  marginLeft: 0,
  marginRight: 0,
}

pe.appendStyle({
  'pretty-error': _.defaults({}, nullStyle),
  'pretty-error > header': nullStyle,
  'pretty-error > header > title > kind': nullStyle,
  'pretty-error > header > title > wrapper': nullStyle,
  'pretty-error > header > colon': nullStyle,
  'pretty-error > header > message': nullStyle,
  'pretty-error > trace': nullStyle,
  'pretty-error > trace > item': _.defaults({

  }, nullStyle),
  'pretty-error > trace > item > header': nullStyle,
  'pretty-error > trace > item > header > pointer > file': nullStyle,
  'pretty-error > trace > item > header > pointer > colon': nullStyle,
  'pretty-error > trace > item > header > pointer > line': nullStyle,
  'pretty-error > trace > item > header > what': nullStyle,
  'pretty-error > trace > item > footer': nullStyle,
  'pretty-error > trace > item > footer > addr': nullStyle,
  'pretty-error > trace > item > footer > extra': nullStyle
})
AriaMinaei commented 9 years ago

Hey @reggi, reading your second and third comment, it looks like you've made progress on your own, so I'm not sure exactly what the question currently is. So could you rehash your question?