Skip to content

Commit 1061fc8

Browse files
authored
Merge pull request #495 from mplsgrant/add-try-excepts
Add try excepts
2 parents ace04ea + c67154a commit 1061fc8

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/warnet/bitcoin.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
22
import re
3+
import sys
34
from datetime import datetime
45
from io import BytesIO
56

67
import click
8+
from urllib3.exceptions import MaxRetryError
79

810
from test_framework.messages import ser_uint256
911
from test_framework.p2p import MESSAGEMAP
@@ -25,7 +27,12 @@ def rpc(tank: str, method: str, params: str):
2527
"""
2628
Call bitcoin-cli <method> [params] on <tank pod name>
2729
"""
28-
print(_rpc(tank, method, params))
30+
try:
31+
result = _rpc(tank, method, params)
32+
except Exception as e:
33+
print(f"{e}")
34+
sys.exit(1)
35+
print(result)
2936

3037

3138
def _rpc(tank: str, method: str, params: str):
@@ -43,7 +50,10 @@ def debug_log(tank: str):
4350
Fetch the Bitcoin Core debug log from <tank pod name>
4451
"""
4552
cmd = f"kubectl logs {tank}"
46-
print(run_command(cmd))
53+
try:
54+
print(run_command(cmd))
55+
except Exception as e:
56+
print(f"{e}")
4757

4858

4959
@bitcoin.command()
@@ -55,7 +65,11 @@ def grep_logs(pattern: str, show_k8s_timestamps: bool, no_sort: bool):
5565
Grep combined bitcoind logs using regex <pattern>
5666
"""
5767

58-
tanks = get_mission("tank")
68+
try:
69+
tanks = get_mission("tank")
70+
except MaxRetryError as e:
71+
print(f"{e}")
72+
sys.exit(1)
5973

6074
matching_logs = []
6175

src/warnet/k8s.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ def get_dynamic_client() -> DynamicClient:
2424

2525
def get_pods() -> V1PodList:
2626
sclient = get_static_client()
27-
return sclient.list_namespaced_pod(get_default_namespace())
27+
try:
28+
pod_list: V1PodList = sclient.list_namespaced_pod(get_default_namespace())
29+
except Exception as e:
30+
raise e
31+
return pod_list
2832

2933

3034
def get_mission(mission: str) -> list[V1PodList]:

0 commit comments

Comments
 (0)