Skip to content
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

"Validation failed" creating prettier checks #718

Closed
tractorcow opened this issue Sep 18, 2023 · 7 comments
Closed

"Validation failed" creating prettier checks #718

tractorcow opened this issue Sep 18, 2023 · 7 comments

Comments

@tractorcow
Copy link

I have this output in my github actions logs

Run wearerequired/lint-action@v2
Adding auth information to Git remote URL
Fetching remote branch "fix/update-github-actions"
From https://github.com/pixelfusion/pixel-fusion-website
Switching to the "fix/update-github-actions" branch
 * branch            fix/update-github-actions -> FETCH_HEAD
 * [new branch]      fix/update-github-actions -> origin/fix/update-github-actions
Previous HEAD position was 5ee48b0 Merge bd014578fc61895ad36dd762fa84af3b86707a4d into 51e708d45eb4a3a2e3ea44b2486715881f077d5d
Switched to branch 'fix/update-github-actions'
SHA of last commit is "bd014578fc61895ad36dd762fa84af3b86707a4d"
Run Prettier
  Verifying setup for Prettier…
  Verified Prettier setup
  Will use Prettier to check the files with extensions css,html,js,json,jsx,md,sass,scss,ts,tsx,vue,yaml,yml
  Linting files in /home/runner/work/pixel-fusion-website/pixel-fusion-website with Prettier …
  Error:  src/components/Icon/Icon.stories.tsx: SyntaxError: ',' expected. (32:3)
  Error:    30 |     },
  Error:    31 |   },
  Error:  > 32 | } satisfies Meta<typeof Icon>
  Prettier found 1 error (failure)
  Error:       |   ^
  Error:    33 |
  Error:    34 | export default meta
  Error:    35 | type Story = StoryObj<typeof Icon>
Create check runs with commit annotations
  Creating GitHub check with failure conclusion and 1 annotations for Prettier…
  Error: Received status code 422. Validation Failed https://docs.github.com/rest/checks/runs#create-a-check-run
Warning: Some check runs could not be created.

Here is the job for this check

  prettier:
    name: Check prettier
    runs-on: ubuntu-latest
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - name: Check out git repository
        uses: actions/checkout@v3
      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18
      - name: Install Node.js dependencies
        run: npm ci
      - name: Code linting
        uses: wearerequired/lint-action@v2
        with:
          prettier: true

Any idea why we are getting Validation Failed on the check creation? It seems to be lint-action is generating a bad api payload, but I'm not sure how to debug this.

@tractorcow
Copy link
Author

Another check in the same repo (eslint: true) passes successfully, so it's not a permission issue. It's only an issue for prettier: true check

Create check runs with commit annotations
  Creating GitHub check with success conclusion and 0 annotations for ESLint…
  ESLint check created successfully

@tractorcow
Copy link
Author

How can I get the payload for the HTTP post to debug?

@tractorcow
Copy link
Author

tractorcow commented Sep 20, 2023

I managed to extract the payload that was causing the 422 error. The issue is "path" is a required field, but not included.

{
   "name":"Prettier",
   "head_sha":"8926cd754ef3fc50cf4f605b55fa686f4da2630c",
   "conclusion":"failure",
   "output":{
      "title":"1 error",
      "summary":"Prettier found 1 error",
      "annotations":[
         {
            "path":"",
            "start_line":1,
            "end_line":1,
            "annotation_level":"failure",
            "message":"There are issues with this file's formatting, please run Prettier to fix the errors"
         }
      ]
   }
}

@tractorcow
Copy link
Author

tractorcow commented Sep 20, 2023

I've tracked the issue to prettier itself; prettier/prettier#13516

I think this module could respond a bit better to prettier erroring. In linters/prettier.js we have this code.

		const paths = output.stdout.split(/\r?\n/);
		lintResult.error = paths.map((path) => ({
			path,
			firstLine: 1,
			lastLine: 1,
			message:
				"There are issues with this file's formatting, please run Prettier to fix the errors",
		}));

However in this case, output.stdout is blank (hence path being an empty string), with the error being in output.stderr.

@tractorcow
Copy link
Author

Updating prettier in my project seemed to solve the issue. I'll close this, sorry for the noise!

@tractorcow
Copy link
Author

I've suggested a minor improvement at #722 to prevent invalid checks being pushed.

@tractorcow
Copy link
Author

Checking output.stderror this is that value. Should I bother to parse this?

[error] src/components/Icon/Icon.stories.tsx: SyntaxError: ',' expected. (32:3)
[error]   30 |     },
[error]   31 |   },
[error] > 32 | } satisfies Meta<typeof Icon>
[error]      |   ^
[error]   33 |
[error]   34 | export default meta
[error]   35 | type Story = StoryObj<typeof Icon>

I could regexp the first line and extract path, error, line, character?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant