This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Buggy _strerror in asyncore
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: giampaolo.rodola Nosy List: Longpoke, eric.araujo, giampaolo.rodola, josiahcarlson
Priority: normal Keywords: easy

Created on 2010-04-29 20:30 by Longpoke, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg104583 - (view) Author: Longpoke (Longpoke) Date: 2010-04-29 20:30
This function in asyncore is buggy:

def _strerror(err):
    res = os.strerror(err)
    if res == 'Unknown error':
        res = errorcode[err]
    return res

- os.strerror may throw ValueError depending on the os, or return a string saying something like: "Unknown error 1234".
- os.strerror never returns "Unknown error" for me, so "Unknown error <err>" is always returned for me (Linux 2.6.32)
- if os.strerrror failed, it's likely that it wont be in errno.errcode either

Maybe it should be written like this:
def _strerror(err):
    try:
        return strerror(err)
    except ValueError:
        return "Unknown error {0}".format(err)
msg104593 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-04-29 21:24
Good catch. I modified your patch a little bit including a catch for OverflowError exception and a last attempt to look up into errno.errorcode:

def _strerror(err):
    try:
        return strerror(err)
    except (ValueError, OverflowError):
        if err in errorcode:
            return errorcode[err]
        return "Unknown error %s" %err

Josiah, what do you think?
msg105059 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-05-05 17:05
Don’t want to bikeshed here, but why didn’t you keep the newer “{}” string formatting? Module consistency?
msg105157 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-05-06 18:53
Yes, I think it's better to remain consistent with the rest of the module which uses %s all around the place, also for backward compatibility in case someone wants to copy asyncore.py shipped with recent python versions and use it in their code using older python versions.

This practice is not so uncommon since asyncore.py received serious bug-fixing only starting from python 2.6.

Fixed in r80875 (2.7), r80876 (3.2), r80878 (2.6) and r80879 (3.1) which also includes changes to fix issue 8483.
msg105998 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-05-18 19:08
I’ve just checked the diff and the current trunk version of the file, and the change from “os.strerror(err)” to “strerror(err)” seems buggy to me.
msg106002 - (view) Author: Longpoke (Longpoke) Date: 2010-05-18 19:43
Yes, it should definately be os.sterror. Dunno how I ended up omitting that, sorry.
msg106005 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-05-18 20:19
It slipped under my radar as well. Thanks.
Fixed in r81294 (trunk), r81298 (2.6), r81299 (3.2) and r81300 (3.1) which also add tests and include NameError in the list of possible exceptions in case os.strerror() is not supported on the current platform (e.g. Windows CE) in which case "unknown error $number$" is returned.
History
Date User Action Args
2022-04-11 14:57:00adminsetgithub: 52819
2010-05-18 20:39:51giampaolo.rodolasetstatus: open -> closed
resolution: fixed
2010-05-18 20:19:06giampaolo.rodolasetmessages: + msg106005
2010-05-18 19:43:50Longpokesetmessages: + msg106002
2010-05-18 19:16:11eric.araujosetmessages: - msg105999
2010-05-18 19:14:34eric.araujosetnosy: + josiahcarlson, giampaolo.rodola
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
messages: + msg105999

assignee: giampaolo.rodola
type: crash -> behavior
2010-05-18 19:08:50eric.araujosetstatus: closed -> open

type: behavior -> crash
assignee: giampaolo.rodola -> (no value)
versions: - Python 3.1, Python 2.7, Python 3.2
nosy: - josiahcarlson, giampaolo.rodola

messages: + msg105998
resolution: fixed -> (no value)
stage: resolved ->
2010-05-06 18:53:14giampaolo.rodolasetstatus: open -> closed
resolution: fixed
messages: + msg105157

stage: resolved
2010-05-05 17:05:58eric.araujosetnosy: + eric.araujo
messages: + msg105059
2010-04-29 21:24:39giampaolo.rodolasetkeywords: + easy
assignee: giampaolo.rodola
messages: + msg104593

versions: + Python 3.1, Python 2.7, Python 3.2
2010-04-29 20:55:20r.david.murraysetnosy: + josiahcarlson, giampaolo.rodola
type: crash -> behavior
2010-04-29 20:30:28Longpokecreate