Skip to content

fix(nodeenv): report the url and proxy instead of a traceback - #410

Merged
ekalinin merged 1 commit into
masterfrom
fix/proxy-error-message
Sep 21, 2026
Merged

ekalinin merged 1 commit into
masterfrom
fix/proxy-error-message

Conversation

@ekalinin

Copy link
Copy Markdown
Owner

Closes #229.

Problem

A download that never reaches a server raises URLError all the way out of main(). The user gets a stack trace that names neither the url nodeenv tried nor the proxy it went through. A broken http_proxy/https_proxy is the usual cause, which is exactly what #229 reported.

Still reproducible on current master:

$ http_proxy=http://:3128 https_proxy=https://:3128 nodeenv --prebuilt test_env
Traceback (most recent call last):
  ...
  File "nodeenv.py", line 1330, in _get_versions_json
    response = urlopen('%s/index.json' % src_base_url)
  File "nodeenv.py", line 923, in urlopen
    return urllib2.urlopen(req)
  ...
urllib.error.URLError: <urlopen error [Errno 61] Connection refused>

Fix

urlopen() now catches URLError, logs the url with the failure reason and whatever proxy variables are set, and exits 1:

$ http_proxy=http://:3128 https_proxy=https://:3128 nodeenv --prebuilt test_env
Error: cannot download https://nodejs.org/download/release/index.json: [Errno 61] Connection refused
Error: check the proxy settings: http_proxy=http://:3128, https_proxy=https://:3128
$ echo $?
1

The SSL-context branching moved into _urlopen(req) so the new handler wraps all three variants at once. Since every download goes through urlopen(), this covers all four call sites: download_node_src(), the two npm paths and index.json.

HTTPError is re-raised untouched. It is a URLError subclass, so a plain except URLError would have swallowed every 404 as well and silently broken the arm64 to x64 fallback in download_node_src().

Tests

  • test_urlopen_reports_the_url_it_failed_to_reach
  • test_urlopen_reports_the_proxy_it_went_through
  • test_urlopen_keeps_raising_http_errors, a regression guard for the arm64 fallback

Also checked by hand: the unresolvable-proxy-host variant from the report, that no environment directory is left behind, and that a normal --list is unaffected.

A download that never reaches a server, which a broken http_proxy or
https_proxy usually causes, raised URLError all the way out of main().
The user got a stack trace naming neither the url nodeenv tried nor the
proxy it went through.

urlopen() now catches URLError, logs the url with the failure reason and
the proxy variables that are set, and exits 1.  HTTPError is re-raised
untouched: it is a URLError subclass, and download_node_src() relies on
it for the arm64 to x64 fallback.

Closes #229
@ekalinin
ekalinin force-pushed the fix/proxy-error-message branch from 933d6f9 to bfcc27c Compare September 21, 2026 18:28
@ekalinin
ekalinin merged commit c6da999 into master Sep 21, 2026
44 checks passed
@ekalinin ekalinin added the bug label Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nodeenv error message for improper proxy address is suboptimal

1 participant