Skip to content

Commit c3ae0a7

Browse files
committed
feat: add configuration for stack trace
1 parent 5885d21 commit c3ae0a7

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

examples/list_jobs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import time
33

44
start = time.time()
5-
tamr_client = TamrApiClient('<host-name>', [('x-api-key', '<api-key>')])
5+
tamr_client = TamrApiClient('<host-name>', [('x-api-key', '<api-key>')], grpc_stack_trace=True)
66
one = time.time()
77

88

tamr_sdk/api_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from tamr_sdk.jobs.jobs_client import JobsClient
22

33
class TamrApiClient:
4-
def __init__(self, host, metadata):
4+
def __init__(self, host, metadata, grpc_stack_trace=False):
55
self.host = host
66
self.metadata = metadata
7+
self.grpc_stack_trace = grpc_stack_trace
78

89
def jobs(self):
9-
return JobsClient(self.host, self.metadata)
10+
return JobsClient(self.host, self.metadata, self.grpc_stack_trace)

tamr_sdk/jobs/jobs_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from tamr_sdk.utils.handler import exception_handler
66

77
class JobsClient:
8-
def __init__(self, host, metadata):
8+
def __init__(self, host, metadata, grpc_stack_trace=False):
99
credentials = grpc.ssl_channel_credentials()
1010
channel = grpc.secure_channel(host, credentials)
1111
self.metadata = metadata
1212
self.stub = JobsStub(channel)
13+
self.grpc_stack_trace = grpc_stack_trace
1314

1415
@exception_handler
1516
def get_job(self, job_id):

tamr_sdk/utils/handler.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,25 @@ def exception_handler(
1414
def handle_grpc_status_codes(
1515
_self: SelfT, *args: ArgT.args, **kwargs: ArgT.kwargs
1616
) -> ReturnT:
17+
grpc_stack_trace = _self.grpc_stack_trace
1718
try:
1819
func(_self, *args, **kwargs)
1920
except grpc._channel._InactiveRpcError as e:
2021
if e.code() == grpc.StatusCode.NOT_FOUND:
21-
raise ValueError(e.details())
22+
if not grpc_stack_trace:
23+
raise ValueError(e.details()) from None
24+
else:
25+
raise ValueError(e.details())
2226
elif e.code() == grpc.StatusCode.UNAVAILABLE:
23-
raise ConnectionError(e.details())
27+
if not grpc_stack_trace:
28+
raise ConnectionError(e.details()) from None
29+
else:
30+
raise ConnectionError(e.details())
2431
elif e.code() == grpc.StatusCode.UNAUTHENTICATED:
25-
raise ConnectionRefusedError(
26-
"Error connecting to client. Authentication is not valid"
27-
)
32+
if not grpc_stack_trace:
33+
raise ConnectionRefusedError("Error connecting to client. Authentication is not valid") from None
34+
else:
35+
raise ConnectionRefusedError("Error connecting to client. Authentication is not valid")
2836
else:
2937
raise e
3038

0 commit comments

Comments
 (0)