<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On May 3, 2021, at 3:11 PM, Chris Smith <<a href="mailto:cdsmith@gmail.com" class="">cdsmith@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thanks, Richard.  This is awesome!</div></div></blockquote><div><br class=""></div><div>Glad you're excited. I am, too!</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">For my use case, the more exciting possibility would be to interact with error messages from JavaScript.  For this reason, I'd definitely love to see a well-known structured file format (JSON, YAML, XML, or whatever) that can be read without linking against GHC.  I also like the idea of producing both the structured data and the raw string, since as you mention, one shouldn't need to handle every single possible GHC diagnostic just to add some special handling for a few of them.</div><div class=""><br class=""></div><div class="">Ultimately, if reading error messages did require linking with GHC, it wouldn't be the end of the world.  I would just write my own translation layer to JSON.  So consider this a weak preference.</div></div></div></blockquote><div><br class=""></div><div>It would be straightforward to, say, define instances of ToJSON and FromJSON for all of our error types. We could then serialize to JSON. The problem would be that these error types are likely to wibble and wobble between releases. (For now, I would say even between minor releases.) So if you don't link against GHC, you would have to stay on your toes to keep your parser up-to-date. Maybe this feature will settle down into a rhythm, and we can start to promise more stability, but I think it would be a mistake to promise that too soon. Linking against GHC protects you from making a mistake in this regard. On the other hand, the JSON output would be perfectly well formed independently of GHC, so there would be no hard requirement to do this linking.</div><div><br class=""></div><div>So that's one vote for JSON (where the JSON also includes the rendered string). Do I hear any others? (Note that these different modes of interaction are all pretty easy to build -- the hard part is the infrastructure supporting them -- so we can likely do more than one.)</div><div><br class=""></div><div>Thanks,</div><div>Richard</div><br class=""><blockquote type="cite" class=""><div class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 3, 2021 at 3:00 PM Richard Eisenberg <<a href="mailto:rae@richarde.dev" class="">rae@richarde.dev</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class="">Hi all,<div class=""><br class=""></div><div class="">Alfredo and I are hard at work redesigning GHC's error-message system. It is time for more input, though, from clients of the system -- those writing IDEs and other tooling on top of GHC.</div><div class=""><br class=""></div><div class="">The key question: How would you like your errors served?</div><div class=""><br class=""></div><div class="">Right now, errors are served well-done: fully cooked into structureless strings that can be easily given to users. The problem with this is that IDEs cannot easily intervene between GHC and the users, as all the nutrition (that is, detailed information) has been cooked away.</div><div class=""><br class=""></div><div class="">The new design allows for *structured errors*, where error messages are represented by elements of some error type. Different messages have different constructors of this type, and these constructors can carry auxiliary information. GHC will store these errors raw and cook them (that is, turn them into readable strings) only right before printing them. If the raw messages were somehow passed to IDEs, then IDEs could handle them non-uniformly. (For example, if a module name and a file name are different, the IDE could just present a dialog to the user asking whether the user would like to change one automatically.) </div><div class=""><br class=""></div><div class="">There are a few open questions:</div><div class=""><br class=""></div><div class="">* In what vessel shall the raw messages be served? In other words, how do IDEs expect to interact with this new system?</div><div class="">  - One route would be to pass e.g. -fjson-errors, which means that GHC presents the raw messages in a JSON format, for IDEs to parse. That's OK, but it still means that IDEs would have to have their own raw error message types to parse into.</div><div class="">  - Another route would be for the IDE to link against GHC itself, and then invoke the compiler via a function call that returns the raw messages directly.</div><div class="">  - Another route is some kind of middle ground, where the IDE passes e.g. -fbinary-errors=<filename> instructing GHC to write out a binary encoding of its messages to some file (or pipe, I suppose). These could then be deserialized back into GHC's own error types, but running in a separate process (linked against GHC, once again).</div><div class="">  - I'm sure you can come up with other interaction strategies.</div><div class=""><br class=""></div><div class="">* What will an IDE do with these messages? It might have special handling for some, but GHC has a lot of different messages, and I imagine IDEs will want many just to be printed to the user. If an IDE has only the raw message, then the IDE is forced to do all the cooking -- no good. So there must be a way to take a raw message and render it into a user-readable string.</div><div class="">  - Maybe the above methods produce both the raw error and the rendered one? Then the IDE can choose which it prefers to use.</div><div class="">  - GHC could easily export its pretty-printing functions that take in the raw messages and produce rendered ones. But that (again) requires linking against GHC.</div><div class=""><br class=""></div><div class="">Note that we are not (here, yet) discussing errors served at points between raw and well-done, though I would like to do so. Such an error would be rendered into a format where textual bits are interleaved with more structured bits, which would enable e.g. clicking on expressions within error messages to get their types. That (important feature) comes separately.</div><div class=""><br class=""></div><div class="">So: what do consumers want here?</div><div class=""><br class=""></div><div class="">Preview: You can take a look at some raw error messages from the driver in <a href="https://gitlab.haskell.org/ghc/ghc/-/merge_requests/5533" target="_blank" class="">https://gitlab.haskell.org/ghc/ghc/-/merge_requests/5533</a>.</div><div class=""><br class=""></div><div class="">Thanks!</div><div class="">Richard</div></div>_______________________________________________<br class="">
ghc-devs mailing list<br class="">
<a href="mailto:ghc-devs@haskell.org" target="_blank" class="">ghc-devs@haskell.org</a><br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></body></html>