From 28d5a321f7a0d76c9c4d5c377bcc2e8db772c3a6 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Fri, 12 Nov 2021 18:30:57 +0100 Subject: [PATCH 1/1] acmecert: Make error reporting more flexible. --- acmecert | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/acmecert b/acmecert index 0ba66e2..f6f60e2 100755 --- a/acmecert +++ b/acmecert @@ -1,9 +1,13 @@ #!/usr/bin/python3 -import sys, os, getopt, binascii, json, pprint, signal, time +import sys, os, getopt, binascii, json, pprint, signal, time, threading import urllib.request import Crypto.PublicKey.RSA, Crypto.Random, Crypto.Hash.SHA256, Crypto.Signature.PKCS1_v1_5 +class msgerror(Exception): + def report(self, out): + out.write("acmecert: undefined error\n") + service = "https://acme-v02.api.letsencrypt.org/directory" _directory = None def directory(): @@ -308,11 +312,16 @@ class maybeopen(object): self.fp.close() return False -class usageerr(Exception): - pass - +invdata = threading.local() commands = {} +class usageerr(msgerror): + def __init__(self): + self.cmd = invdata.cmd + + def report(self, out): + out.write("%s\n" % (self.cmd.__doc__,)) + def cmd_reg(args): "usage: acmecert reg [OUTPUT-FILE]" acct = register() @@ -447,9 +456,13 @@ def main(argv): usage(sys.stderr) sys.exit(1) try: - cmd(args) - except usageerr: - sys.stderr.write("%s\n" % (cmd.__doc__,)) + try: + invdata.cmd = cmd + cmd(args) + finally: + invdata.cmd = None + except msgerror as exc: + exc.report(sys.stderr) sys.exit(1) if __name__ == "__main__": -- 2.11.0