Add support for CLI-formatted errors and allow for dead code elimination #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current
DebugReport
has a couple of issues:The error message fields are HTML-escaped. This makes them difficult to read in a CLI context, especially anywhere we do something like
trace.Errorf("some error message: %q", "some relevant information")
. Here's an example of what a debug report can currently produce:Error messages "bubbled up" through many layers in Teleport can have significantly more escaping, making logs painful to read.
Using the golang templating removes the possibility of dead code elimination, because it calls
reflect.MethodByName
.This PR adds a new interface (for backwards compatibility), which adds separate HTML and CLI debug report functions. The HTML versions produce identical error messages as the (now depreciated)
DebugReport()
functions. The CLI versions produce messages in the same format, but without any escaping.The PR also changes the underlying templating implementation to use a string builder rather than a template. This makes the code slightly harder to read, but removes the reflection dependency. While this is unlikely to make any different in Teleport product binaries, it should reduce the binary size of some of our internal tools. It should have a positive impact on the ~600 non-Gravitational consumers of this library as well.