After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 684314 - Wrong error messages for out of range numbers
Wrong error messages for out of range numbers
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2012-09-18 18:08 UTC by Ángel Guzmán Maeso (shakaran)
Modified: 2012-09-28 05:59 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Ángel Guzmán Maeso (shakaran) 2012-09-18 18:08:43 UTC
This report is a little corner case. But I report for ensure a good quality and avoid future mistakes.

I made four test cases regarding Soup.Address in python binding.

I test corner cases for ports. Since I can have users with errors or mistakes in configs, it could be propagated in my code. So the test are for negative ports, port as strings, floats or floats with decimals no rounded. This no detect all problems, but I find special the 1º test with a confuse message exception (maybe it is a problem with pygobject print message). Also in floats, the conversion is made automatically, and no warning is launched, so if a float value is casted to int wrongly, you could get a different port in a special case.

The examples:

from gi.repository import Soup 

# 1º test case
address = '127.0.0.1'
port = -1 # integer negative  => confuse message, probably a error parsing message exception data

try:
    interface = Soup.Address.new(address, port)
except ValueError as e: # Validate and catch errors introduced by the user, just in case
    print ('Error creating address ' + address + ' for port ' + str(port) + ': ' + str(e)) 
    
# 2º test case
address = '127.0.0.1'
port = 'nointegervalue' # string => good exception message

try:
    interface = Soup.Address.new(address, port)
except ValueError as e: # Validate and catch errors introduced by the user, just in case
    print ('Error creating address ' + address + ' for port ' + str(port) + ': ' + str(e)) 
except TypeError as e:
    print ('Error creating address ' + address + ' for port ' + str(port) + ': ' + str(e)) 

# 3º test case    
address = '127.0.0.1'
port = 80.000 # float => automatic casting to 80 without warning

try:
    interface = Soup.Address.new(address, port)
except ValueError as e: # Validate and catch errors introduced by the user, just in case
    print ('Error creating address ' + address + ' for port ' + str(port) + ': ' + str(e)) 
   
interface.resolve_sync(None)
print ('Port:' + str(interface.get_port()))

# 4º test case   
address = '127.0.0.1'
port = 80.001 # float with decimals  => automatic casting to 80 without warning

try:
    interface = Soup.Address.new(address, port)
except ValueError as e: # Validate and catch errors introduced by the user, just in case
    print ('Error creating address ' + address + ' for port ' + str(port) + ': ' + str(e)) 
    
interface.resolve_sync(None)
print ('Port:' + str(interface.get_port()))

"""
Result:
$ python3 test.py 
Error creating address 127.0.0.1 for port -1: %lli not in range %i to %u
Error creating address 127.0.0.1 for port nointegervalue: Must be number, not str
Port:80
Port:80
"""
Comment 1 Dan Winship 2012-09-18 18:50:39 UTC
All of this behavior comes from pygobject, not libsoup. The "%lli not in range %i to %u" message is clearly a bug. I think the rounding floats to ints is considered a feature.
Comment 2 Martin Pitt 2012-09-28 05:59:38 UTC
Ah, according to http://docs.python.org/c-api/string.html#PyString_FromFormat %lli is not a valid format specifier for PyErr_Format(). It needs to be %lld instead, so we can't use G_GINT64_FORMAT and friends. That particular %lli was hardcoded.

Fixed in
http://git.gnome.org/browse/pygobject/commit/?id=34270a109d2af20391c80e88874ee7303eaf5c09

Thanks for the report!