Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Ensure that BotServerError.message is properly returned. #1096

Closed
wants to merge 1 commit into from

1 participant

@staer

BotoServerError inherits from StandardError which defines the message attribute (to None if it isn't defined as the lone parameter to the constructor). This causes the getattr lookup to find the superclass version of "message" which is None resulting in unexpected behavior when getting the message from a server failure.

Instead of getattr for the 'message' attribute, set it after parsing the XML in the constructor.

@staer staer Ensure that execption.message is properly returned.
Because BotoServerError inherits from StandardError which defines message, __getattr_ will return None instead of the value contained in "error_message". Change the constructor to properly set message after getting it from the XML response.
46c06ae
@staer

Looks like this was fixed in b944f4b

@staer staer closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 5, 2012
  1. @staer

    Ensure that execption.message is properly returned.

    staer authored
    Because BotoServerError inherits from StandardError which defines message, __getattr_ will return None instead of the value contained in "error_message". Change the constructor to properly set message after getting it from the XML response.
This page is out of date. Refresh to see the latest.
View
4 boto/exception.py
@@ -93,9 +93,9 @@ def __init__(self, status, reason, body=None, *args):
self.error_message = self.body
self.body = None
+ self.message = self.error_message
+
def __getattr__(self, name):
- if name == 'message':
- return self.error_message
if name == 'code':
return self.error_code
raise AttributeError
View
0  tests/unit/exceptions/__init__.py
No changes.
View
15 tests/unit/exceptions/test_server_error.py
@@ -0,0 +1,15 @@
+try:
+ import unittest2 as unittest
+except ImportError:
+ import unittest
+
+from boto.exception import BotoServerError
+
+class BotoServerErrorTest(unittest.TestCase):
+ def setUp(self):
+ self.body = """<?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchKey</Code><Message>The resource you requested does not exist</Message><Resource>/mybucket/myfoto.jpg</Resource> <RequestId>4442587FB7D0A2F9</RequestId></Error>"""
+
+ def test_exception_message(self):
+ e = BotoServerError(404, "No Such Key", body=self.body)
+ self.assertEqual("NoSuchKey", e.code)
+ self.assertEqual("The resource you requested does not exist", e.message)
Something went wrong with that request. Please try again.