AriaMinaei / pretty-error

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

Support for HTML #12

Closed tusharmath closed 9 years ago

tusharmath commented 9 years ago

There should be a way to prettify the error messages in html form. So that one can use it as a middleware for express.

AriaMinaei commented 9 years ago

Would this be enough:

$ npm install pretty-error renderkid domutils

then:

PrettyError = require 'pretty-error'
renderkidTools = require 'renderkid/lib/tools'
DomUtils = require 'domutils'

pe = new PrettyError

errorObject = new Error "error message"
shortDomNotation = pe.getObject errorObject 
errorDom = renderkidTools.objectToDom errorObject
errorHtml = DomUtils.getOuterHTML errorDom

console.log errorHtml

The output would be:

<pretty-error>
  <header>
    <title>
      ...
tusharmath commented 9 years ago

Will this output a pretty version of the stacktrace on the browser?

AriaMinaei commented 9 years ago

Just the HTML without any CSS, so you'd need to write some CSS to make it look pretty.

If you want to use the console's theme in the browser, there are two ways to do that:

  1. You can simply write pretty-error's theme in css for the browser, manually.
  2. You could write a function that takes prettyError._renderer._styles (which is the object that handles the stylesheet rules in RenderKid), and converts it to pure CSS rules. Most of RenderKid's css can be directly converted to CSS. The bullet points are implemented differently though, so you'll have to come up with a way to convert RenderKid's bullet property to a browser-readable CSS property.

The second way is automatic, but I think it's an overkill. I'd recommend just rewriting PrettyError's CSS rules by hand.

AriaMinaei commented 9 years ago

I'm closing this issue since it hasn't been active for a while.

tusharmath commented 9 years ago

Not the right reason to close the issu .

AriaMinaei commented 9 years ago

No problem. Let me know if my explanation in this comment was useful. I'll be happy to help with implementing a separate HTML converter for pretty-error.

pjebs commented 5 years ago

Can you reopen this.

It would be good if it returned pure html with inline css styling just like https://github.com/benbria/exception-formatter does.

That way we can use the output directly in a website.