Skip to content

Commit

Permalink
Improve NotFound exception message to include namespace (#479)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
jacobtomlinson and pre-commit-ci[bot] authored Aug 23, 2024
1 parent 7709c06 commit 5b8e71c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions kr8s/_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ async def async_exists(self, ensure=False) -> bool:
if status == 200:
return True
if ensure:
raise NotFoundError(f"Object {self.name} does not exist")
raise NotFoundError(
f"Object {self.name} does not exist in {self.namespace}"
)
return False

async def create(self) -> None:
Expand Down Expand Up @@ -337,7 +339,9 @@ async def delete(self, propagation_policy: str | None = None) -> None:
self.raw = resp.json()
except ServerError as e:
if e.response and e.response.status_code == 404:
raise NotFoundError(f"Object {self.name} does not exist") from e
raise NotFoundError(
f"Object {self.name} does not exist in {self.namespace}"
) from e
raise e

async def refresh(self) -> None:
Expand All @@ -357,7 +361,9 @@ async def async_refresh(self) -> None:
self.raw = resp.json()
except ServerError as e:
if e.response and e.response.status_code == 404:
raise NotFoundError(f"Object {self.name} does not exist") from e
raise NotFoundError(
f"Object {self.name} does not exist in {self.namespace}"
) from e
raise e

async def patch(self, patch, *, subresource=None, type=None) -> None:
Expand Down Expand Up @@ -386,7 +392,9 @@ async def async_patch(self, patch: dict, *, subresource=None, type=None) -> None
self.raw = resp.json()
except ServerError as e:
if e.response and e.response.status_code == 404:
raise NotFoundError(f"Object {self.name} does not exist") from e
raise NotFoundError(
f"Object {self.name} does not exist in {self.namespace}"
) from e
raise e

async def scale(self, replicas: int | None = None) -> None:
Expand Down

0 comments on commit 5b8e71c

Please sign in to comment.