Skip to content
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

matrix: HANDLE EXCEPTIONS OMG #4

Closed
jahschwa opened this issue Jan 20, 2017 · 3 comments
Closed

matrix: HANDLE EXCEPTIONS OMG #4

jahschwa opened this issue Jan 20, 2017 · 3 comments
Assignees

Comments

@jahschwa
Copy link
Owner

The matrix protocol does not handle failure to connect correctly, bringing down the entire bot. Although the relevant line is wrapped in a try statement, except MatrixRequestError as e: doesn't catch the exception because it's raised directly by requests and not translated/recast by the matrix api.

2017-01-20 10:48:58 | sibylbot | CRI | UNHANDLED: ConnectionError

Traceback (most recent call last):
  File "/media/Data/git/sibyl/lib/sibylbot.py", line 1057, in run_forever
    self.__run_forever()
  File "/media/Data/git/sibyl/lib/sibylbot.py", line 968, in __run_forever
    self.__serve()
  File "/media/Data/git/sibyl/lib/sibylbot.py", line 948, in __serve
    proto.connect()
  File "protocols/sibyl_matrix.py", line 183, in connect
    token = self.client.login_with_password(user,pw)
  File "/home/laptopdude/python/lib/matrix_client/client.py", line 151, in login_with_password
    "m.login.password", user=username, password=password
  File "/home/laptopdude/python/lib/matrix_client/api.py", line 125, in login
    return self._send("POST", "/login", content)
  File "/home/laptopdude/python/lib/matrix_client/api.py", line 449, in _send
    verify=self.validate_cert
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 53, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 437, in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPSConnectionPool(host='matrix.org', port=443): Max retries exceeded with url: /_matrix/client/api/v1/login (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f2ae9477f10>: Failed to establish a new connection: [Errno 101] Network is unreachable',))

Reproducing: enable the matrix protocol and try to run Sibyl without working internet

@jahschwa
Copy link
Owner Author

jahschwa commented Apr 14, 2017

2017-04-14 09:26:00 | sibylbot | CRI | UNHANDLED: MatrixRequestError

Traceback (most recent call last):
  File "/home/sibyl/lib/sibylbot.py", line 1094, in run_forever
    self.__run_forever()
  File "/home/sibyl/lib/sibylbot.py", line 1003, in __run_forever
    self.__idle_proc()
  File "/home/sibyl/lib/sibylbot.py", line 1044, in __idle_proc
    self.__idle_send()
  File "/home/sibyl/lib/sibylbot.py", line 1075, in __idle_send
    self.__send(*self.__pending_send.get())
  File "/home/sibyl/lib/sibylbot.py", line 717, in __send
    to.get_protocol().send(text,to)
  File "protocols/sibyl_matrix.py", line 285, in send
    to.room.send_text(text)
  File "/home/osmc/src/matrix-client/matrix_client/room.py", line 40, in send_text
    return self.client.api.send_message(self.room_id, text)
  File "/home/osmc/src/matrix-client/matrix_client/api.py", line 238, in send_message
    self.get_text_body(text_content, msgtype)
  File "/home/osmc/src/matrix-client/matrix_client/api.py", line 211, in send_message_event
    return self._send("PUT", path, content)
  File "/home/osmc/src/matrix-client/matrix_client/api.py", line 482, in _send
    code=response.status_code, content=response.text
MatrixRequestError: 503: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>503 Service Unavailable</title>
</head><body>
<h1>Service Unavailable</h1>
<p>The server is temporarily unable to service your
request due to maintenance downtime or capacity
problems. Please try again later.</p>
<hr>
<address>Apache/2.4.7 (Ubuntu) Server at terracrypt.net Port 443</address>
</body></html>

@jahschwa jahschwa changed the title matrix kills bot when failing to connect matrix: HANDLE EXCEPTIONS OMG Apr 14, 2017
@jahschwa jahschwa added minutes and removed external labels Nov 30, 2017
@jahschwa
Copy link
Owner Author

Seems no longer blocked externally after:
matrix-org/matrix-python-sdk#123

@jfrederickson
Copy link
Collaborator

Resolved along with #28.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants