Closed jantimon closed 6 years ago
The code that you're looking for is here:
Calling pe.getObject()
would return an object describing the structure of the final rendered error object:
const e = new Error('blah')
const obj = pe.getObject(e)
If you inspect obj
, you'll see that it has all the information there is about the original error object.
Now, since your goal is to ultimately print the error as an html document, you'll basically have two options:
obj
and returns "<html>...</html>"
. This is what I would do.RenderKid
that takes the obj
and refines it further. It works like this: const renderKid = pe._renderer; const refinedDom = renderKid._toDom(obj)
. In this method, refinedDom
is actually a DOM tree compatible with htmlparser2. What you can do with it is to stringify it (similar to HTMLElement#innerHTML
) using this function. Just take note that _toDom()
and _renderer
are private properties, so they may change or be removed in the future.Isn't that sth you could easily provide so I don't have to build a large code around pretty-error?
If enough people wanted this, then it might make sense to provide it out of the box. Otherwise, it's just wasted effort that complicates the code base.
the html-webpack-plugin which makes heavy use of pretty error is downloaded million times a week so it would aid many users and javascript is very web focused so providing a html presentation might also help other use cases
Hey @AriaMinaei
I am using
pretty-error
for thehtml-webpack-plugin
.The error is logged to the console and also added to the result html file.
Would it be possible to render the error message also as a html (including a style tag)?