From eed4a945348b61fb2b5758a8d46331c9b7e22fbe Mon Sep 17 00:00:00 2001 From: Andrew Pan Date: Mon, 6 Mar 2023 12:10:42 -0600 Subject: [PATCH] reformat, fully type new errors --- sigstore/_cli.py | 2 +- sigstore/_errors.py | 11 +++++------ sigstore/_internal/tuf.py | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/sigstore/_cli.py b/sigstore/_cli.py index 92e5482c8..d6753ab88 100644 --- a/sigstore/_cli.py +++ b/sigstore/_cli.py @@ -27,6 +27,7 @@ from sigstore_protobuf_specs.dev.sigstore.bundle.v1 import Bundle from sigstore import __version__ +from sigstore._errors import Error from sigstore._internal.ctfe import CTKeyring from sigstore._internal.fulcio.client import DEFAULT_FULCIO_URL, FulcioClient from sigstore._internal.keyring import Keyring @@ -37,7 +38,6 @@ ) from sigstore._internal.tuf import TrustUpdater from sigstore._utils import PEMCert -from sigstore._errors import Error from sigstore.oidc import ( DEFAULT_OAUTH_ISSUER_URL, STAGING_OAUTH_ISSUER_URL, diff --git a/sigstore/_errors.py b/sigstore/_errors.py index c0e0f2f47..d512d52bb 100644 --- a/sigstore/_errors.py +++ b/sigstore/_errors.py @@ -17,7 +17,6 @@ """ import sys - from textwrap import dedent from typing import Any, Mapping @@ -30,7 +29,7 @@ def diagnostics(self) -> str: return """An issue occurred.""" - def print_and_exit(self, raise_error=False): + def print_and_exit(self, raise_error: bool = False) -> None: """Prints all relevant error information to stderr and exits.""" remind_verbose = ( @@ -59,7 +58,7 @@ def print_and_exit(self, raise_error=False): class NetworkError(Exception): """Raised when a connectivity-related issue occurs.""" - def diagnostics(self): + def diagnostics(self) -> str: return """A network issue occurred. Check your internet connection and try again. @@ -69,7 +68,7 @@ def diagnostics(self): class TUFError(Exception): """Raised when a TUF error occurs.""" - def __init__(self, message): + def __init__(self, message: str): self.message = message from tuf.api import exceptions @@ -78,7 +77,7 @@ def __init__(self, message): exceptions.DownloadError: NetworkError().diagnostics() } - def diagnostics(self): + def diagnostics(self) -> str: details = TUFError._details.get( type(self.__context__), "Please report this issue at .", @@ -93,5 +92,5 @@ def diagnostics(self): class MetadataError(Exception): """Raised when TUF metadata does not conform to the expected structure.""" - def diagnostics(self): + def diagnostics(self) -> str: return f"""{str(self)}.""" diff --git a/sigstore/_internal/tuf.py b/sigstore/_internal/tuf.py index 9e7f75282..1e228d1e6 100644 --- a/sigstore/_internal/tuf.py +++ b/sigstore/_internal/tuf.py @@ -25,11 +25,11 @@ import appdirs from cryptography.x509 import Certificate, load_pem_x509_certificate -from tuf.ngclient import RequestsFetcher, Updater from tuf.api import exceptions as TUFExceptions +from tuf.ngclient import RequestsFetcher, Updater +from sigstore._errors import MetadataError, TUFError from sigstore._utils import read_embedded -from sigstore._errors import TUFError, MetadataError logger = logging.getLogger(__name__)