Invalid HTTPS_PROXY values are reported as unexpected Hardhat errors
A user can set HTTPS_PROXY or HTTP_PROXY to a value that looks reasonable but isn’t a valid URL, for example:
HTTPS_PROXY=127.0.0.1:8888 # no protocolIn that case, Hardhat doesn’t make it clear that the problem is the environment variable, and the error depends on which command happens to hit it.
For network requests, it shows an unexpected internal error with a full stack trace and asks the user to report a Hardhat bug:
$ HTTPS_PROXY=127.0.0.1:8888 npx hardhat run scripts/foo.ts --network sepolia
An unexpected error occurred:
DispatcherError: Failed to create dispatcher: The proxy url configured in the
HTTPS_PROXY environment variable is not a valid url
at ... (20 more lines)
If you think this is a bug in Hardhat, please report it here: https://hardhat.org/report-bugFor downloads, the same problem gets wrapped as a failure to reach the target server:
$ HTTPS_PROXY=127.0.0.1:8888 npx hardhat build
Error HHE110003 in plugin hardhat-slang-solx: Couldn't download the checksum for
solx 0.1.8 from https://solx-releases-mirror.hardhat.org/... : Failed to create
dispatcher: The proxy url configured in the HTTPS_PROXY environment variable is
not a valid urlAn invalid proxy value is a configuration error, so it should be reported as a regular Hardhat error. Ideally the message should name the variable, show the expected format (http://host:port), and avoid both the stack trace and the suggestion to file a bug.
Since the cause is the same in every case, the error should also be consistent regardless of which request happens to trigger it. We shouldn’t include the raw proxy value in the message, since proxy URLs can contain credentials.
Source: NomicFoundation/hardhat