Should catch and wrap socket errors

Bug #929308 reported by James Westby
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
piston-mini-client
Fix Released
Medium
Anthony Lenton

Bug Description

Hi,

I got the below traceback showing that when the other end refuses connections
you get a raw socket error back. I think catching and transforming it to be
an APIError would be good as a user of the library, as I can catch just the one
exception type.

Thanks,

James

  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/sourcecode/../src/djpkgme/tests/test_harness.py", line 114, in test__send_api_request_failure
    e = self.assertRaises(RuntimeError, ws._send_api_request, metadata)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/testtools/testcase.py", line 388, in assertRaises
    self.assertThat(our_callable, matcher)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/testtools/testcase.py", line 400, in assertThat
    mismatch = matcher.match(matchee)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/testtools/matchers.py", line 798, in match
    mismatch = self.exception_matcher.match(exc_info)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/testtools/matchers.py", line 546, in match
    mismatch = matcher.match(matchee)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/testtools/testcase.py", line 380, in match
    reraise(*matchee)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/testtools/matchers.py", line 791, in match
    result = matchee()
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/testtools/testcase.py", line 793, in __call__
    return self._callable_object(*self._args, **self._kwargs)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/sourcecode/../src/djpkgme/harness.py", line 158, in _send_api_request
    api.build_package(metadata, {})
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/piston_mini_client/__init__.py", line 73, in wrapper
    body = func(*args, **kwargs)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/sourcecode/../src/djpkgme/client.py", line 40, in build_package
    return self._post('/build_package/', data=data)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/piston_mini_client/__init__.py", line 340, in _post
    headers=headers, scheme=scheme)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/piston_mini_client/__init__.py", line 463, in _request
    method=method, body=body, headers=headers)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1445, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1197, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1133, in _conn_request
    conn.connect()
  File "/home/jw2328/devel/pkgme-service/old-piston-mini-client-api/virtualenv/local/lib/python2.7/site-packages/httplib2/__init__.py", line 799, in connect
    raise socket.error, msg
error: [Errno 111] Connection refused

Related branches

Changed in piston-mini-client:
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Jonathan Lange (jml) wrote :

How did you produce this error? When I tried calling a service that was down, I got an APIError.

Revision history for this message
James Westby (james-w) wrote :

That I can't remember now.

Maybe it's fixed in a newer version of piston_mini_client or httplib2 and you were using that?

In https://code.launchpad.net/~jml/software-center-agent/call-pkgme/+merge/89589 you apparently
found the same thing though, so I don't think this is specific to my environment or anything.

Thanks,

James

Changed in piston-mini-client:
status: Confirmed → In Progress
assignee: nobody → Anthony Lenton (elachuni)
Changed in piston-mini-client:
milestone: none → 0.7.4
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.