Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tools/upip.py: avoid list out of range exception #6018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

agners
Copy link
Contributor

@agners agners commented May 7, 2020

On ESP32 devices, when the gateway or DNS serer is not a valid,
getaddrinfo returns an empty list. This leads to the rather unhelpful
error message when using upip.install(..):
Error installing 'micropython-umqtt.simple': list index out of range,
packages may be partially installed

Make sure a helpful error message is printed in this case.

On ESP32 devices, when the gateway or DNS serer is not a valid,
getaddrinfo returns an empty list. This leads to the rather unhelpful
error message when using upip.install(..):
  Error installing 'micropython-umqtt.simple': list index out of range,
  packages may be partially installed

Make sure a helpful error message is printed in this case.
@agners agners force-pushed the avoid-list-out-of-range-message branch from 258ab4f to b60f042 Compare May 7, 2020 23:36
@tve
Copy link
Contributor

tve commented May 8, 2020

FYI, this is a bug in getaddrinfo which is fixed in #5982.

@agners
Copy link
Contributor Author

agners commented May 9, 2020

@tve cool, thanks for that fix! It definitly fixed the issue I encountered, where the DNS server is not valid.

However, if a DNS name does not exist, getaddrinfo returns an empty list, which is not well handled:

>>> upip.index_urls.insert(0, "https://weiredpipwhichdoesnotexist.org/pi")
>>> upip.install("micropython-umqtt.simple")
Installing to: /lib/
Error installing 'micropython-umqtt.simple': list index out of range, packages may be partially installed

So I guess this fix still makes sense. But if we do not want to clutter code with unnecessary checks I am also fine with closing it.

@tve
Copy link
Contributor

tve commented May 9, 2020

However, if a DNS name does not exist, getaddrinfo returns an empty list, which is not well handled:

Nope, it raises an OSError, consistent with CPython:

>>> socket.getaddrinfo("nonexistant.example.com", 80)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: -202

@dpgeorge dpgeorge added the tools Relates to tools/ directory in source, or other tooling label Jul 22, 2021
@dpgeorge
Copy link
Member

With #5982, getaddrinfo() should never return an empty list. So this PR is not needed.

@dpgeorge dpgeorge closed this Jul 22, 2021
tannewt added a commit to tannewt/circuitpython that referenced this pull request Oct 22, 2022
Check for connected before calling read. Otherwise TinyUSB may
setup the read on the wrong endpoint.

Fixes micropython#6018
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Relates to tools/ directory in source, or other tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants