core: Log InvalidCABundle error in info buffer

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-04-04 21:53:34 +02:00
parent 12af2c5e47
commit 1338fcf9b9
2 changed files with 23 additions and 6 deletions

View file

@ -29,9 +29,11 @@ from typing import (
TYPE_CHECKING,
)
from xml.etree import ElementTree as ET
from pathlib import Path
from slixmpp import Iq, JID, InvalidJID
from slixmpp.util import FileSystemPerJidCache
from slixmpp.xmlstream.xmlstream import InvalidCABundle
from slixmpp.xmlstream.handler import Callback
from slixmpp.exceptions import IqError, IqTimeout, XMPPError
@ -674,6 +676,26 @@ class Core:
self.do_command(''.join(char_list), True)
self.doupdate()
def loop_exception_handler(self, loop, context) -> None:
"""Do not log unhandled iq errors and timeouts"""
handled_exceptions = (IqError, IqTimeout, InvalidCABundle)
if not isinstance(context['exception'], handled_exceptions):
loop.default_exception_handler(context)
elif isinstance(context['exception'], InvalidCABundle):
paths = context['exception'].path
error = (
'Poezio could not find a valid CA bundle file automatically. '
'Ensure the ca_cert_path configuration is set to a valid '
'CA bundle path, generally provided by the \'ca-certificates\' '
'package in your distribution.'
)
if isinstance(paths, (str, Path)):
# error += '\nFound the following value: {path}'.format(path=str(path))
paths = [paths]
if paths is not None:
error += f"\nThe following values were tried: {str([str(s) for s in paths])}"
self.information(error, 'Error')
def save_config(self):
"""
Save config in the file just before exit

View file

@ -115,17 +115,12 @@ def main():
from slixmpp.exceptions import IqError, IqTimeout
def swallow_iqerrors(loop, context):
"""Do not log unhandled iq errors and timeouts"""
if not isinstance(context['exception'], (IqError, IqTimeout)):
loop.default_exception_handler(context)
# Warning: asyncio must always be imported after the config. Otherwise
# the asyncio logger will not follow our configuration and won't write
# the tracebacks in the correct file, etc
import asyncio
loop = asyncio.get_event_loop()
loop.set_exception_handler(swallow_iqerrors)
loop.set_exception_handler(cocore.loop_exception_handler)
loop.add_reader(sys.stdin, cocore.on_input_readable)
loop.add_signal_handler(signal.SIGWINCH, cocore.sigwinch_handler)