Skip to content

Commit

Permalink
service: Log exceptions in more cases (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeryan authored Sep 8, 2023
1 parent 92a2b97 commit aeeb4d9
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions ni_measurementlink_service/_loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def intercept_unary_unary(
call = continuation(client_call_details, request)
# call.add_callback(call_logger.close)
return _LoggingResponseCallFuture(call_logger, call)
except Exception:
call_logger.close()
except Exception as e:
call_logger.close(e)
raise
else:
return continuation(client_call_details, request)
Expand All @@ -80,8 +80,8 @@ def intercept_unary_stream(
call_iterator = continuation(client_call_details, request)
# call_iterator.add_callback(call_logger.close)
return _LoggingResponseCallIterator(call_logger, call_iterator)
except Exception:
call_logger.close()
except Exception as e:
call_logger.close(e)
raise
else:
return continuation(client_call_details, request)
Expand All @@ -103,8 +103,8 @@ def intercept_stream_unary(
)
# call.add_callback(call_logger.close)
return _LoggingResponseCallFuture(call_logger, call)
except Exception:
call_logger.close()
except Exception as e:
call_logger.close(e)
raise
else:
return continuation(client_call_details, request_iterator)
Expand All @@ -126,8 +126,8 @@ def intercept_stream_stream(
)
# call_iterator.add_callback(call_logger.close)
return _LoggingResponseCallIterator(call_logger, call_iterator)
except Exception:
call_logger.close()
except Exception as e:
call_logger.close(e)
raise
else:
return continuation(client_call_details, request_iterator)
Expand Down Expand Up @@ -204,8 +204,8 @@ def _log_unary_stream(
) -> Iterator[grpc.TResponse]:
try:
return _LoggingResponseIterator(call_logger, handler_function(request, context))
except Exception:
call_logger.close()
except Exception as e:
call_logger.close(e)
raise

def _log_stream_unary(
Expand All @@ -232,8 +232,8 @@ def _log_stream_stream(
call_logger,
handler_function(_LoggingRequestIterator(call_logger, request_iterator), context),
)
except Exception:
call_logger.close()
except Exception as e:
call_logger.close(e)
raise


Expand Down Expand Up @@ -391,9 +391,12 @@ def __next__(self) -> _T:
response = next(self._inner_iterator)
self._call_logger.log_streaming_response()
return response
except (StopIteration, Exception):
except StopIteration:
self._call_logger.close()
raise
except Exception as e:
self._call_logger.close(e)
raise


if TYPE_CHECKING:
Expand Down Expand Up @@ -464,6 +467,9 @@ def __next__(self) -> _T:
response = next(self._inner_call_iterator) # type: ignore[call-overload]
self._call_logger.log_streaming_response()
return response
except (StopIteration, Exception):
except StopIteration:
self._call_logger.close()
raise
except Exception as e:
self._call_logger.close(e)
raise

0 comments on commit aeeb4d9

Please sign in to comment.