Skip to content

Commit

Permalink
Merge pull request #35 from ThomasWaldmann/exceptions
Browse files Browse the repository at this point in the history
store: raise BE specific exception, fixes #34
  • Loading branch information
ThomasWaldmann committed Sep 11, 2024
2 parents 225b666 + db06b9b commit 80e526b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/borgstore/backends/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ class BackendError(Exception):
"""Base class for exceptions in this module."""


class BackendURLInvalid(BackendError):
"""Raised when trying to create a store using an invalid backend URL."""


class NoBackendGiven(BackendError):
"""Raised when trying to create a store and not giving a backend nor a URL."""


class BackendAlreadyExists(BackendError):
"""Raised when a backend already exists."""

Expand Down
6 changes: 3 additions & 3 deletions src/borgstore/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from .utils.nesting import nest
from .backends._base import ItemInfo, BackendBase
from .backends.errors import ObjectNotFound # noqa
from .backends.errors import ObjectNotFound, NoBackendGiven, BackendURLInvalid # noqa
from .backends.posixfs import get_file_backend
from .backends.sftp import get_sftp_backend
from .constants import DEL_SUFFIX
Expand All @@ -43,9 +43,9 @@ def __init__(self, url: Optional[str] = None, backend: Optional[BackendBase] = N
if backend is None and url is not None:
backend = get_backend(url)
if backend is None:
raise ValueError(f"Invalid Backend Storage URL: {url}")
raise BackendURLInvalid(f"Invalid Backend Storage URL: {url}")
if backend is None:
raise ValueError("You need to give a backend instance or a backend url.")
raise NoBackendGiven("You need to give a backend instance or a backend url.")
self.backend = backend
self._stats: Counter = Counter()
# this is to emulate additional latency to what the backend actually offers:
Expand Down

0 comments on commit 80e526b

Please sign in to comment.