netlify / cli

Netlify Command Line Interface
http://cli.netlify.com
MIT License
1.56k stars 343 forks source link

422 "No records matched" error when deploying #6403

Open ali-kamalizade opened 5 months ago

ali-kamalizade commented 5 months ago

Describe the bug

I am adding multi-language support to one of our web apps. We use GitHub actions to deploy new versions. This has worked so far but since changing the structure of our app the deployment appears to fail rather often. The error logs mention a 422 unprocessable entity error.

The file structure in the file browser looks like this:

But the deployment itself seems (?) to have worked as the changes seem to be available in production hence it might be something after the deployment that the Netlify CLI is attempting to do which causes our GitHub workflow to fail.

Error logs ```bash ✔ Finished uploading blobs to deploy store - Hashing files... - Looking for a functions cache... ✔ Deploying functions from cache (use --skip-functions-cache to override) ✔ Finished hashing 741 files and 4 functions - CDN diffing files... ✔ CDN requesting 8 files and 0 functions - Uploading 10 files › Warning: JSONHTTPError: No records matched 422 › Warning: { "name": "JSONHTTPError", "status": 422, "json": { "code": 422, "message": "No records matched" } } ​ Save updated config ──────────────────────────────────────────────────────────────── ​ (options.onEnd completed in 172ms) ​ Internal error during "options.onPostBuild" ──────────────────────────────────────────────────────────────── ​ Error message JSONHTTPError: Unprocessable Entity ​ Error location During options.onPostBuild at parseResponse (file:///home/runner/work/web-app/web-app/node_modules/netlify-cli/node_modules/netlify/lib/methods/response.js:10:39) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async callMethod (file:///home/runner/work/web-app/web-app/node_modules/netlify-cli/node_modules/netlify/lib/methods/index.js:26:28) at async tryUpload (file:///home/runner/work/web-app/web-app/node_modules/netlify-cli/dist/utils/deploy/upload-files.js:80:29) { name: 'JSONHTTPError', status: 422, json: { code: 422, message: 'No records matched' } } ```

Steps to reproduce

It is hard to reproduce reliably but here is my best guess:

  1. Change a lot of files
  2. Run the deployment command: npx netlify deploy --prod --build --filter apps/web-app

Configuration

[build]
  publish = "dist/web-app"
  command = "npm run build:main-app"
  functions = "./functions"
  environment = { NODE_ENV = "development", NODE_VERSION = "20.6.1" }
[[plugins]]
  package = "@netlify/plugin-functions-install-core"

# Since this is a single page application, we need to redirect all requests to the index.html file
[[redirects]]
  from = "/en/*"
  to = "/en/index.html"
  status = 200

[[redirects]]
  from = "/de/*"
  to = "/de/index.html"
  status = 200

# fallback for URLs without language prefix
[[redirects]]
  from = "/*"
  to = "/en/index.html"
  status = 200

Environment

I am using netlify-cli@17.16.3.

System:
    OS: macOS 14.3.1
    Memory: 1.50 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
Binaries:
    Node: 20.6.1 - ~/.nvm/versions/node/v20.6.1/bin/node
    npm: 9.8.1 - ~/.nvm/versions/node/v20.6.1/bin/npm
kitop commented 3 months ago

Hi @ali-kamalizade do you have a reproduction case you can share with files and everything? We're investigating and having something reproducible would help a ton. Thanks!

ali-kamalizade commented 3 months ago

Hi @ali-kamalizade do you have a reproduction case you can share with files and everything? We're investigating and having something reproducible would help a ton. Thanks!

Hi @kitop , thank you for your reply!

Unfortunately, I can't share any reproduction. What I do think is it may simply be related to the size. In our case, the folders (en, de - see the file structure above) have basically the same size. Right now it's ~28MB per folder. Hence, before we did the localization we only had to deploy 28MB while the size needed to be uploaded to Netlify has now been doubled (2 * 28MB = 56MB). I also have to state that it does not fail all the time (the worst kind of bugs: e.g. it failed 1/4 times today).

kitop commented 3 months ago

Gotcha. Are the files in the en and de directories all different? do you share some? I'm curious as well if there are symlinks or if the build process is modifying these files somehow. Anything you can share about the structure and the build process would be super helpful to continue debugging. Thanks!

ali-kamalizade commented 3 months ago

Gotcha. Are the files in the en and de directories all different? do you share some? I'm curious as well if there are symlinks or if the build process is modifying these files somehow. Anything you can share about the structure and the build process would be super helpful to continue debugging. Thanks!

The files are basically the same: when doing a production build, the builder goes through the HTML and TypeScript files to replace any marked texts with the ones in the respective translation files (XLF). We are using the i18n capabilities of Angular. Hence the project structure looks like a typical Angular project, containing index.html, JS bundles, scripts (e.g. analytics) and assets (e.g. app logo). Hope this helps!

kitop commented 3 months ago

Thanks! One last question: do you have any plugins or integrations in your build process? I'm mostly curious of anything that can run onBuild or similar.

ali-kamalizade commented 3 months ago

Thanks! One last question: do you have any plugins or integrations in your build process? I'm mostly curious of anything that can run onBuild or similar.

Not that I'm aware of, it's a pretty simple setup and we don't use any Netlify build plugins. It's basically running the production build and then deploying it right away with the Netlify CLI as part of our GitHub workflow.