Bot stops running if error reporting fails
codl opened this issue · comments
I've been running a bot with ananas for years now and occasionally it gets stucks and stops running its interval functions anymore, I could not figure out why for the longest time, but I think I've got it: it's when an error occurs during normal function and subsequent error reporting fails.
I have an admin
set in the bot's config, the bot encounters an error (say, the server is down), the default error handler tries to report the error by sending a DM to the admin, which also doesn't work because the server is down, and it goes completely silent until I restart ananas.
An example log
[2023-08-08 01:53:01] apod.accept_one_page_of_follow_requests: Exception encountered in @interval function: MastodonInternalServerError('Mastodon API returned error', 500, 'Internal Server Error', None)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/ananas/ananas.py", line 377, in interval_threadproc
f()
File "/usr/local/lib/python3.10/site-packages/apod/__init__.py", line 360, in accept_one_page_of_follow_requests
follow_requests = self.mastodon.follow_requests()
File "/usr/local/lib/python3.10/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/usr/local/lib/python3.10/site-packages/mastodon/utility.py", line 49, in wrapper
return function(self, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/mastodon/relationships.py", line 71, in follow_requests
return self.__api_request('GET', '/api/v1/follow_requests', params)
File "/usr/local/lib/python3.10/site-packages/mastodon/internals.py", line 297, in __api_request
raise ex_type('Mastodon API returned error', response_object.status_code, response_object.reason, error_msg)
mastodon.errors.MastodonInternalServerError: ('Mastodon API returned error', 500, 'Internal Server Error', None)
Exception in thread Thread-1 (interval_threadproc):
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/ananas/ananas.py", line 377, in interval_threadproc
f()
File "/usr/local/lib/python3.10/site-packages/apod/__init__.py", line 360, in accept_one_page_of_follow_requests
follow_requests = self.mastodon.follow_requests()
File "/usr/local/lib/python3.10/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/usr/local/lib/python3.10/site-packages/mastodon/utility.py", line 49, in wrapper
return function(self, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/mastodon/relationships.py", line 71, in follow_requests
return self.__api_request('GET', '/api/v1/follow_requests', params)
File "/usr/local/lib/python3.10/site-packages/mastodon/internals.py", line 297, in __api_request
raise ex_type('Mastodon API returned error', response_object.status_code, response_object.reason, error_msg)
mastodon.errors.MastodonInternalServerError: ('Mastodon API returned error', 500, 'Internal Server Error', None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.10/site-packages/ananas/ananas.py", line 380, in interval_threadproc
self.report_error(error, f.__name__)
File "/usr/local/lib/python3.10/site-packages/ananas/ananas.py", line 509, in report_error
f(error)
File "/usr/local/lib/python3.10/site-packages/ananas/ananas.py", line 498, in default_report_handler
self.mastodon.status_post(("@{} ERROR REPORT from {}:\n{}"
File "/usr/local/lib/python3.10/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/usr/local/lib/python3.10/site-packages/mastodon/utility.py", line 49, in wrapper
return function(self, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/mastodon/statuses.py", line 248, in status_post
return self.__status_internal(
File "/usr/local/lib/python3.10/site-packages/mastodon/statuses.py", line 182, in __status_internal
return self.__api_request('POST', '/api/v1/statuses', params, headers=headers, use_json=use_json)
File "/usr/local/lib/python3.10/site-packages/mastodon/internals.py", line 297, in __api_request
raise ex_type('Mastodon API returned error', response_object.status_code, response_object.reason, error_msg)
mastodon.errors.MastodonInternalServerError: ('Mastodon API returned error', 500, 'Internal Server Error', None)
Note the second exception that happens within the default error handler