google / google/go-jsonnet

Custom Error Formatting

Open
#453 2 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
1.8k
Forks
263
PR merge metrics
No merged PRs in 30d

Description

Hey!

I would like to implement a custom `jsonnet.ErrorFormatter`, mostly because I would like to do screen formatting a bit different:

- `RUNTIME` / `STATIC` / `INTERNAL ERROR` in red
- newline before stacktrace
- stacktrace in grey

These are visual preferences and probably not worth discussing here.

However, I figured this was much harder than expected. While the `ErrorFormatter` interface exists, it cannot effectively be implemented:

- `Format()` receives multiple kinds of errors, it needs to decide how to render them individually
- `termErrorFormatter` solves this using a type switch. **BUT**: `errors.StaticError` is `internal`, so I cannot implement that very type switch myself
- `termErrorFormatter` is private, so I cannot re-use code from it. This forces me to copy that code over to do slight modifications

The use of `internal` in this repository has historically made it hard to implement certain features in downstream projects (https://github.com/google/go-jsonnet/pull/395, https://github.com/google/go-jsonnet/pull/327).

Is there a strong reason to do this? Because I would really like to import, compose and hack with all code of this repository, without certain subsets being reserved for use in here exclusively :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.