diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2022-12-20 17:31:39 -0500 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2022-12-20 17:33:12 -0500 |
commit | 67fd1910174cc0d46a5bd5782cbbe2baf612a0f7 (patch) | |
tree | 6a3918f0be91ee8cb6cebd23a205d261c3cfd2b0 | |
parent | f96638aa20ff83b7800bfa20114aab38996961f3 (diff) | |
download | b4-67fd1910174cc0d46a5bd5782cbbe2baf612a0f7.tar.gz |
ez: give better error message when patatt signing fails
Avoid giving an obtuse traceback when we don't find any usable keys
(patatt or PGP) and suggest what the user can do to fix the problem.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | b4/__init__.py | 21 | ||||
-rw-r--r-- | b4/ez.py | 20 |
2 files changed, 29 insertions, 12 deletions
diff --git a/b4/__init__.py b/b4/__init__.py index 08f9033..761c3b8 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -3212,6 +3212,12 @@ def send_mail(smtp: Union[smtplib.SMTP, smtplib.SMTP_SSL, None], msgs: Sequence[ tosend = list() if output_dir is not None: dryrun = True + # Do we have an endpoint defined? + config = get_main_config() + endpoint = config.get('send-endpoint-web', '') + if not re.search(r'^https?://', endpoint): + endpoint = None + for msg in msgs: if not msg.get('X-Mailer'): msg.add_header('X-Mailer', f'b4 {__VERSION__}') @@ -3247,7 +3253,15 @@ def send_mail(smtp: Union[smtplib.SMTP, smtplib.SMTP_SSL, None], msgs: Sequence[ if patatt_sign: import patatt # patatt.logger = logger - bdata = patatt.rfc2822_sign(bdata) + try: + bdata = patatt.rfc2822_sign(bdata) + except patatt.NoKeyError as ex: + logger.critical('CRITICAL: Error signing: no key configured') + logger.critical(' Run "patatt genkey" or configure "user.signingKey" to use PGP') + logger.critical(' As a last resort, rerun with --no-sign') + raise RuntimeError(str(ex)) + except patatt.SigningError as ex: + raise RuntimeError('Failure trying to patatt-sign: %s' % str(ex)) if dryrun: if output_dir: filen = '%s.eml' % ls.get_slug(sep='-') @@ -3273,11 +3287,6 @@ def send_mail(smtp: Union[smtplib.SMTP, smtplib.SMTP_SSL, None], msgs: Sequence[ return 0 logger.info('---') - # Do we have an endpoint defined? - config = get_main_config() - endpoint = config.get('send-endpoint-web', '') - if not re.search(r'^https?://', endpoint): - endpoint = None if use_web_endpoint and endpoint: if reflect: logger.info('Reflecting via web endpoint %s', endpoint) @@ -1490,9 +1490,13 @@ def cmd_send(cmdargs: argparse.Namespace) -> None: logger.critical(' Please re-enable signing or use SMTP') sys.exit(1) - sent = b4.send_mail(None, send_msgs, fromaddr=None, patatt_sign=True, - dryrun=cmdargs.dryrun, output_dir=cmdargs.output_dir, use_web_endpoint=True, - reflect=cmdargs.reflect) + try: + sent = b4.send_mail(None, send_msgs, fromaddr=None, patatt_sign=True, + dryrun=cmdargs.dryrun, output_dir=cmdargs.output_dir, use_web_endpoint=True, + reflect=cmdargs.reflect) + except RuntimeError as ex: + logger.critical('CRITICAL: %s', ex) + sys.exit(1) else: try: smtp, fromaddr = b4.get_smtp(dryrun=cmdargs.dryrun) @@ -1501,9 +1505,13 @@ def cmd_send(cmdargs: argparse.Namespace) -> None: logger.critical(ex) sys.exit(1) - sent = b4.send_mail(smtp, send_msgs, fromaddr=fromaddr, patatt_sign=sign, - dryrun=cmdargs.dryrun, output_dir=cmdargs.output_dir, use_web_endpoint=False, - reflect=cmdargs.reflect) + try: + sent = b4.send_mail(smtp, send_msgs, fromaddr=fromaddr, patatt_sign=sign, + dryrun=cmdargs.dryrun, output_dir=cmdargs.output_dir, use_web_endpoint=False, + reflect=cmdargs.reflect) + except RuntimeError as ex: + logger.critical('CRITICAL: %s', ex) + sys.exit(1) logger.info('---') if cmdargs.dryrun: |