maetl / calyx

A Ruby library for generating text with recursive template grammars.
MIT License
61 stars 5 forks source link

Friendly error handling #13

Closed maetl closed 7 years ago

maetl commented 8 years ago

This has never really been prioritised as much as it should have been, but I have left some affordances in the internals—mostly around refactoring towards centralised lookups in the registry—to manage it better in future.

The main focus of the error messages should be to provide succinct and precise information about where the error occurred and what can be done to fix it.

Most of the time, this is going to be related to the generator attempting to expand a symbol that doesn’t exist in the grammar, so I think I want to put most of the effort into raising a specifically designed exception (with a well written message) for this particular use case.

maetl commented 7 years ago

Finally—after more than a year—I got around to addressing this in 0.15.

Rule symbols that expand to a missing rule now trace the line number of where the rule was defined.

This isn’t perfect, and has meant some broad changes to the internals which could be much improved. But the quality of the error reporting has increased substantially. It’s far less annoying and confusing to track down bugs in a grammar now. You can actually see the exact rule that is causing the problem via the exception message, rather than an incomprehensible stack trace with no direct relationship to the grammar rules.

Happy to close this now, as the overall objective has been addressed.