Skip to content

pkg/mgrconfig: report line and column on parse config error #6016

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

Open
Slava0135 opened this issue May 9, 2025 · 3 comments
Open

pkg/mgrconfig: report line and column on parse config error #6016

Slava0135 opened this issue May 9, 2025 · 3 comments

Comments

@Slava0135
Copy link

Is your feature request related to a problem? Please describe.

Example error message when there is error in syz manager cfg file:

failed to parse config file: invalid character ']' looking for beginning of value

Not very informative, could be better.

Describe the solution you'd like

Something like this:

failed to parse config file: invalid character ']' looking for beginning of value at <line>:<col>
***also source line maybe***
@a-nogikh
Copy link
Collaborator

That would be nice, indeed.

But it would not be a one-line fix unfortunately.

  1. We remove comments before parsing the JSON, which must be accounted for

    // Remove comment lines starting with #.
    data = regexp.MustCompile(`(^|\n)\s*#[^\n]*`).ReplaceAll(data, nil)

  2. Go's json library only points at the offset from the beginning of the input data, it doesn't care about line numbers
    https://pkg.go.dev/encoding/json#SyntaxError

@Slava0135
Copy link
Author

Slava0135 commented May 12, 2025

Maybe consider using hjson format (it has comment support) and it also accepts normal json.
Haven't used it though, not sure if their error information is better.

https://github.com/hjson/hjson-go

@dvyukov
Copy link
Collaborator

dvyukov commented May 12, 2025

Or perhaps YAML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants