question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MDAPI REST Deploy - `Unexpected token < in JSON at position` -- incorrect exit code

See original GitHub issue

Summary

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:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:41 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
shetzelcommented, Mar 16, 2021

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 the SFDX_REST_DEPLOY env var to workaround any REST deploy errors.

1reaction
ricofairsailcomcommented, Mar 16, 2021

The issue is only for Windows machine apparently, just downgrading to v7.81 should work. npm install --global sfdx-cli@7.81.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: Unexpected token < in JSON at position 0
The error seems to be called in an infinite loop presumably as React continuously tries to connect to the server and eventually crashes...
Read more >
Metadata API Developer Guide
Metadata is data that describes other data. To understand how Salesforce defines metadata, contrast business data with Salesforce metadata.
Read more >
How to fix Unexpected Token in JSON error (for ... - YouTube
Not a programmer? Read this! ** - If you get this error in an app you didn't make, and/or you're not a web...
Read more >
Continuous Integration Using Jenkins with SalesforceDX
We will use the OAuth JSON Web Token (JWT) bearer flow that's ... check the status of this deployment, run "sfdx force:mdapi:deploy:report"
Read more >
salesforcedx - "--json --loglevel fatal ended with exit code 1"
I was also facing the same error but did not find anything here. If your deployment is failing, so you need to go...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found