Skip to content

JSON-compatible error outputs #453

@JohnnyMorganz

Description

@JohnnyMorganz

(Converting to an issue so I do not keep forgetting, originally requested by @telemachus in #93 (comment))


We now have a --output-format=json flag, but this currently outputs diffs in json when using --check, not errors.

We could update the env-logger builder to output json for general errors in https://github.com/JohnnyMorganz/StyLua/blob/master/src/cli/main.rs#L327-L353, but we would also want to special case error handling for parse errors (so that we can return data about the location) at https://github.com/JohnnyMorganz/StyLua/blob/master/src/cli/main.rs#L79-L80 and https://github.com/JohnnyMorganz/StyLua/blob/master/src/cli/main.rs#L118-L119

I was thinking of an error structure something like

{
    "type": "error", // or "warn"/"info"/"debug" etc. and "parse_error"
    "message": "XYZ"
}

and if type == "parse_error" we also have a filename and location field like

{
    "type": "parse_error",
    "message": "XYZ",
    "filename": "src/test.lua",
    "location": {
        "start": 0, // byte offset from start of file
        "start_line": 0,
        "start_column": 0,
        "end": 0, // byte offsets from start of file
        "end_line": 0,
        "end_column": 0,
    }
}

Originally posted by @JohnnyMorganz in #93 (reply in thread)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions