merge annotate and describe, more options for controlling how nodes print
leafo opened this issue · comments
There are currently two nodes that control how a node is printed:
describe
- overwrites the "describe" method which essentially is thetostring
callback for a nodeannotate
- changed failure messages include the value it attempted to parse alongside the failure message (keep in mind values are not printed by default for security reasons, imagine a series of shell escape codes to mess up your terminal in an untrusted value you are validating)
The idea of controlling how a node prints, wither during failed parse or description should be merged into single node that can be customized based on the needs. Here are some potential features of the node
- overwriting how a node describes itself (aka the current describe node)
- enabling printing of the value along with the error message (aka the current annotate functionality)
- adding a prefix or suffix to the error message
- custom error message callback including value and original failure message as arguments (currently
format_error
option argument passed to annotate) - Special support for aggregate types and collecting the errors from all of them individually (it could be cool if you could have a way of outputting errors as json or an object)
Notes for compatibility:
- The describe node was never exported, it was only available through the describe method on the type baseclass
- The annotate node was exported, so it should continue to exist with a similar API
A good path going forward might be remove the describe node and make the annotate node responsible. The current annotate nodes takes only a single opts argument so it already has a flexible interface.
Another option is to remove these nodes entirely, and insert this functionality in the base class for all types. All types would have to ensure to support it. Then, have methods like annotate or describe on the node that copy and return a new node with the customized parameters.