MDAPI REST Deploy - `Unexpected token < in JSON at position` -- incorrect exit code
See original GitHub issueSummary
Deploying to a fresh scratch org using the REST Metadata API sometimes results in deployment errors, often ~15-30 minutes after org creation, it works until it doesn’t. Those errors aren’t handled well and the result ended in “success” exit code (0) when it should be error (1+).
Errors in parsing a JSON message that is actually an HTML message causes everything to break and not handle the error correctly.
SyntaxError: Unexpected token < in JSON at position 1
(The REST API crashing soon after creation I will be opening a support case for, this is specifically about the DX failings)
Steps To Reproduce:
Repository to reproduce: sfdx-deployfailure-example
I have an example repository and the README has steps to run a script that creates an org, sets it to deploy via REST, then deploys until it breaks. It doesn’t break 100% of the time but I’m probably seeing ~70+% failure rates, though each run could take 30+ minutes to test before giving up on it.
Expected result
Edge cases should be handled properly and when SFDX crashes it should result in a non-zero exit code.
Actual result
SFDX crashes out and prints to the STDERR channel but returns an exit code of 0 reporting success. This has been a huge problem is automated scripts that don’t realize a deployment failed before moving on to the next step.
Additional information
See the README in the repo.
SFDX CLI Version(to find the version of the CLI engine run sfdx --version):
sfdx-cli/7.85.1-2fb9e41053 win32-x64 node-v12.18.3
SFDX plugin Version(to find the version of the CLI plugin run sfdx plugins --core)
sfdx-cli 7.85.1
OS and version: Windows 10
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:41 (13 by maintainers)
For those of you seeing this error:
You have sent us an Illegal URL or an improperly formatted request.
Please provide as many details as you can. At a minimum, CLI version and salesforcedx plugin version. OS. The command with parameters (values can be obfuscated or fake). If possible, get the URL that was used in the request. Choose whatever tool you like to do that or optionally debug the code.As was stated earlier in this thread you can switch to use SOAP instead of REST by
sfdx config:set restDeploy=false
or theSFDX_REST_DEPLOY
env var to workaround any REST deploy errors.The issue is only for Windows machine apparently, just downgrading to v7.81 should work. npm install --global sfdx-cli@7.81.0