atlassian / atlassian/better-ajv-errors
show original file contents in error
- Dominant language
- JavaScript
- Stars
- 245
- Forks
- 50
- PR merge metrics
- No merged PRs in 30d
Description
I'm sure I'm missing something very obvious here, but I started using this package and thought it was exactly what I wanted until I noticed that the "lines" it prints are not actually lines from the source. For example, I write this YAML:
```yaml
input_alphabet: [0, 1]
start_state: q0
accept_states: [q0]
delta:
q0:
0: q0
1: q1
```
and because it is missing a required field `states`, the error message prints
```
REQUIRED Missing required field - DFA must have: states, input_alphabet, start_state, accept_states, delta
> 1 | {
| ^ ☹️ states is missing here!
2 | "input_alphabet": [
3 | "0",
4 | "1"
```
Note in particular that the "file" is not the actual parsed file, but a re-created JSON with extra newlines (originally there is one line `input_alphabet: [0, 1]` but now there are four lines specifying that property).
I realize I'm using this to parse YAML, not JSON, but presumably this would also plague JSON files unless they happened to choose to have the exact same whitespace as in the reconstructed JSON.
I thought I must be missing something obvious, because I cannot possibly see the point of carefully pointing the user to the precise line and column where the error occurred, in a fake file whose line numbers are completely different from the line numbers of the actual original source that they typed.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the reported missing-states validation error using the YAML example and inspect how the package generates the displayed source excerpt. Trace whether the formatter receives the original text or only reconstructed data; done means the error excerpt preserves the user's original lines and line numbering for this case, including when parsing JSON.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100