dotnet / docker-tools

This is a repo to house some common tools for our various docker repos.
MIT License
122 stars 46 forks source link

Improve templating error reporting #1324

Closed lbussell closed 3 months ago

lbussell commented 3 months ago

Our previous error reporting only reported the file that template errors are in and then dumped some of the template text out.

This PR improves it by actually printing which line and column the errors are on. The error location format is {startLine},{startColumn},{endLine},{endColumn}, in order to comply with VS Code's problem matching syntax.

With a custom template generation task and problem matcher, this allows us to get accurate error reporting for template generation:

{
    "label": "Generate Dockerfiles",
    "type": "shell",
    "command": "pwsh ./eng/dockerfile-templates/Get-GeneratedDockerfiles.ps1",
    "group": "build",
    "problemMatcher": [
        {
            "owner": "generate-dockerfiles",
            "fileLocation": [
                "relative",
                "${workspaceFolder}"
            ],
            "pattern": [
                {
                    "regexp": "^(?: )*Template parsing error in file (.*):(.*)(?: )*$",
                    "file": 1,
                    "location": 2
                },
                {
                    "regexp": "^(?: )*Message: (.*)$",
                    "message": 1
                }
            ]
        }
    ]
},

image

dotnet-issue-labeler[bot] commented 3 months ago

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

dotnet-issue-labeler[bot] commented 3 months ago

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.