yuzutech / annotations-action

GitHub action to create annotations from a JSON file
MIT License
31 stars 15 forks source link

Getting an "Unexpected token: error when parsing the JSON output. #59

Closed dweaver33 closed 2 years ago

dweaver33 commented 2 years ago

I'm getting the error SyntaxError: Unexpected token : in JSON at position 2 when running against the following JSON:

[
    {
        "file": "models/linting_test.sql",
        "line": 9,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #4",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 10,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #4",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 14,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L036: Select targets should be on a new line unless there is only one select target.",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 15,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #10",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 16,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #10",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 18,
        "start_column": 15,
        "end_column": 15,
        "title": "SQLFluff",
        "message": "L009: Files must end with a single trailing newline.",
        "annotation_level": "failure"
    }
]
dweaver33 commented 2 years ago

Seems related this: https://github.com/sqlfluff/sqlfluff-github-actions/issues/15

So maybe not an issue here?

ggrossetie commented 2 years ago

Not sure, your JSON seems valid... 🤔 We are using JSON.parse (nothing fancy) and I can confirm that the following is running fine:

const result = JSON.parse(`[
    {
        "file": "models/linting_test.sql",
        "line": 9,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #4",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 10,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #4",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 14,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L036: Select targets should be on a new line unless there is only one select target.",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 15,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #10",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 16,
        "start_column": 5,
        "end_column": 5,
        "title": "SQLFluff",
        "message": "L003: Indent expected and not found compared to line #10",
        "annotation_level": "failure"
    },
    {
        "file": "models/linting_test.sql",
        "line": 18,
        "start_column": 15,
        "end_column": 15,
        "title": "SQLFluff",
        "message": "L009: Files must end with a single trailing newline.",
        "annotation_level": "failure"
    }
]`)

console.log({result})

Might be an encoding issue or an invalid character somewhere (non-breaking space, zero-width space...). For reference, here's the relevant code:

https://github.com/yuzutech/annotations-action/blob/20b64eca4373a29c0ff1014fb4b0d054089f3c77/index.js#L123-L124

dweaver33 commented 2 years ago

Hi @Mogztter, I actually ended up fixing this by implementing the fix described here: https://github.com/sqlfluff/sqlfluff-github-actions/issues/15#issuecomment-1030598058

Seems like it might be more of a dbt issue.