pretty
pretty copied to clipboard
Adding support for printing file context
Howdy! Wanted to throw an idea out there to see if there's interest in this library to add a feature where:
The inputs would specify the keys: :file, :context, :line, :col, :message and there'd a general way to print this out, similar to how prettierjs renders linting output.
This function would be used to generate output like this:
SyntaxError: Unexpected token, expected "," (10:29)
8 | return <div className='HelloWorld' title={`You are visitor number ${ num }`} onMouseOver={onMouseOver}>
9 |
> 10 | <strong>{ greetingce( 0 1 ).toUpperCase() + greeting.slice(1).toLowerCase() }</strong>
| ^
11 | {greeting.endsWith(",") ? " " : <span style={{color: '\grey'}}>", "</span> }
12 | <em>
13 | { greeted }
This would benefit from using the ansi escape codes to highlight line 10 as an example!
I can create a PR if it sounds inline with the pretty library's goals.
Other libraries have done this kind of thing: figure out the source, read it, output it as part of the exception report.
My concern is that too often the failure actually occurs inside clojure.core code, even though the bug is elsewhere in user code.
Thanks for responding @hlship. I think I might have done a poor job explaining the intent of this suggestion.
I agree with you that the error could be in clojure.core. This issue is not proposing to change the exception printer to use this output.
What I'm suggesting is to implement the mechanics of pretty printing a file with line context inside this library, perhaps io.aviso.file-printer. This may be useful to other folks, in similar vein to the other useful namespaces in pretty, i.e. clipboard, ansi, component.
Obviously, pretty hasn't been my focus for a while, and I don't know that it needs to do anything for this particular use case, which isn't about pretty exception output.
Yes, that's slightly disingenuous since the binary output stuff and some of the other bits are not so closely aligned, but that was all 8 - 10 years ago.
@hlshipThis makes sense! Thank you for maintaining this library 👍