Skip to content

Commit

Permalink
feat(sentry): Adding explicit capture for exceptions (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanWoodard authored Nov 13, 2024
1 parent 9da0c84 commit b8211a1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions devservices/commands/list_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from argparse import ArgumentParser
from argparse import Namespace

from sentry_sdk import capture_exception

from devservices.utils.console import Console
from devservices.utils.services import find_matching_service

Expand All @@ -29,6 +31,7 @@ def list_dependencies(args: Namespace) -> None:
try:
service = find_matching_service(service_name)
except Exception as e:
capture_exception(e)
console.failure(str(e))
exit(1)

Expand Down
5 changes: 5 additions & 0 deletions devservices/commands/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from argparse import ArgumentParser
from argparse import Namespace

from sentry_sdk import capture_exception

from devservices.constants import MAX_LOG_LINES
from devservices.exceptions import DependencyError
from devservices.exceptions import DockerComposeError
Expand Down Expand Up @@ -32,6 +34,7 @@ def logs(args: Namespace) -> None:
try:
service = find_matching_service(service_name)
except Exception as e:
capture_exception(e)
console.failure(str(e))
exit(1)

Expand All @@ -49,6 +52,7 @@ def logs(args: Namespace) -> None:
try:
remote_dependencies = install_and_verify_dependencies(service)
except DependencyError as de:
capture_exception(de)
console.failure(str(de))
exit(1)
try:
Expand All @@ -60,6 +64,7 @@ def logs(args: Namespace) -> None:
options=["-n", MAX_LOG_LINES],
)
except DockerComposeError as dce:
capture_exception(dce)
console.failure(f"Failed to get logs for {service.name}: {dce.stderr}")
exit(1)
for log in logs_output:
Expand Down
5 changes: 5 additions & 0 deletions devservices/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from argparse import ArgumentParser
from argparse import Namespace

from sentry_sdk import capture_exception

from devservices.exceptions import DependencyError
from devservices.exceptions import DockerComposeError
from devservices.utils.console import Console
Expand Down Expand Up @@ -35,6 +37,7 @@ def start(args: Namespace) -> None:
try:
service = find_matching_service(service_name)
except Exception as e:
capture_exception(e)
console.failure(str(e))
exit(1)

Expand All @@ -52,6 +55,7 @@ def start(args: Namespace) -> None:
service, force_update_dependencies=True
)
except DependencyError as de:
capture_exception(de)
status.failure(str(de))
exit(1)
try:
Expand All @@ -63,6 +67,7 @@ def start(args: Namespace) -> None:
options=["-d"],
)
except DockerComposeError as dce:
capture_exception(dce)
status.failure(f"Failed to start {service.name}: {dce.stderr}")
exit(1)
# TODO: We should factor in healthchecks here before marking service as running
Expand Down
5 changes: 5 additions & 0 deletions devservices/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from argparse import ArgumentParser
from argparse import Namespace

from sentry_sdk import capture_exception

from devservices.exceptions import DependencyError
from devservices.exceptions import DockerComposeError
from devservices.utils.console import Console
Expand Down Expand Up @@ -67,6 +69,7 @@ def status(args: Namespace) -> None:
try:
service = find_matching_service(service_name)
except Exception as e:
capture_exception(e)
console.failure(str(e))
exit(1)

Expand All @@ -78,6 +81,7 @@ def status(args: Namespace) -> None:
try:
remote_dependencies = install_and_verify_dependencies(service)
except DependencyError as de:
capture_exception(de)
console.failure(str(de))
exit(1)
try:
Expand All @@ -89,6 +93,7 @@ def status(args: Namespace) -> None:
options=["--format", "json"],
)
except DockerComposeError as dce:
capture_exception(dce)
console.failure(f"Failed to get status for {service.name}: {dce.stderr}")
exit(1)

Expand Down
5 changes: 5 additions & 0 deletions devservices/commands/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from argparse import ArgumentParser
from argparse import Namespace

from sentry_sdk import capture_exception

from devservices.exceptions import DependencyError
from devservices.exceptions import DockerComposeError
from devservices.utils.console import Console
Expand Down Expand Up @@ -36,6 +38,7 @@ def stop(args: Namespace) -> None:
try:
service = find_matching_service(service_name)
except Exception as e:
capture_exception(e)
console.failure(str(e))
exit(1)

Expand All @@ -57,6 +60,7 @@ def stop(args: Namespace) -> None:
try:
remote_dependencies = install_and_verify_dependencies(service)
except DependencyError as de:
capture_exception(de)
status.failure(str(de))
exit(1)
remote_dependencies = get_non_shared_remote_dependencies(
Expand All @@ -70,6 +74,7 @@ def stop(args: Namespace) -> None:
remote_dependencies,
)
except DockerComposeError as dce:
capture_exception(dce)
status.failure(f"Failed to stop {service.name}: {dce.stderr}")
exit(1)

Expand Down
5 changes: 4 additions & 1 deletion devservices/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from importlib import metadata

import sentry_sdk
from sentry_sdk import capture_exception
from sentry_sdk.integrations.argv import ArgvIntegration

from devservices.commands import list_dependencies
Expand Down Expand Up @@ -52,9 +53,11 @@ def main() -> None:
try:
check_docker_compose_version()
except DockerDaemonNotRunningError as e:
capture_exception(e)
console.failure(str(e))
exit(1)
except DockerComposeInstallationError:
except DockerComposeInstallationError as e:
capture_exception(e)
console.failure("Failed to ensure docker compose is installed and up-to-date")
exit(1)
parser = argparse.ArgumentParser(
Expand Down

0 comments on commit b8211a1

Please sign in to comment.