Skip to content

Commit

Permalink
reformat, fully type new errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tnytown committed Mar 6, 2023
1 parent 3fbed8c commit eed4a94
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion sigstore/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
11 changes: 5 additions & 6 deletions sigstore/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""

import sys

from textwrap import dedent
from typing import Any, Mapping

Expand All @@ -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 = (
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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 <https://github.com/sigstore/sigstore-python/issues/new>.",
Expand All @@ -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)}."""
4 changes: 2 additions & 2 deletions sigstore/_internal/tuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down

0 comments on commit eed4a94

Please sign in to comment.