- Fork 1.4k
UX: better error message for json errors while parsing options #4602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This predominantly tries to actually list the problematic part of the options.
nextNewLineIndex := max(bytes.IndexByte(data[e.Offset:], '\n'), len(data)-1) | ||
|
||
info := strings.TrimSpace(string(data[previousNewLineIndex:nextNewLineIndex])) | ||
err = fmt.Errorf("parsing options from script got error while parsing %q: %w", info, e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The function name looks pretty generic, while in a large package, and while this error formatting operation is quite specific, thus I'm concerned someone could use it by mistake (expecting it to behave in a more generic way). Wdyt? Perhaps we can set a slightly more concrete name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't mind longer functions, I usually find it useful to bring related functionality together. So, this function can go into a closure in the populateExport
function if we want to avoid others using it as a generic function. Doing so will also save us from finding a better name for it. No strong opinion, though :)
The original idea of #4602 was to report at least the key with potentially the option in question. Due to the lack of support from the error - it can't parse it. The commit was trying to get everything between the previous and next new line. But in practice was getting anything until the end, both because of error in the coed to get the index, but also because there were no newlines due to how we marshal the data before that. This should fix both and make it less likely we just get everything until the end.
The original idea of #4602 was to report at least the key with potentially the option in question. Due to the lack of support from the error - it can't parse it. The commit was trying to get everything between the previous and next new line. But in practice was getting anything until the end, both because of error in the coed to get the index, but also because there were no newlines due to how we marshal the data before that. This should fix both and make it less likely we just get everything until the end. Co-authored-by: Oleg Bespalov <oleg.bespalov@grafana.com> Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com>
What?
This predominantly tries to actually list the problematic part of the options.
Why?
Hopefully help users figure out what the problem is
Checklist
make check
) and all pass.Checklist: Documentation (only for k6 maintainers and if relevant)
Please do not merge this PR until the following items are filled out.
Related PR(s)/Issue(s)