Updating handler.dart

Adding stack trace to more calls of _sendError by using records.

This should allow for more accurate logging and debugging of issues in custom errorHandlers.
This commit is contained in:
tobias 2023-09-06 17:38:55 +02:00
parent dae290cc5a
commit 95733f6806
1 changed files with 15 additions and 15 deletions

View File

@ -184,9 +184,9 @@ class ServerHandler extends ServiceCall {
_service = service!; _service = service!;
_descriptor = descriptor; _descriptor = descriptor;
final error = await _applyInterceptors(); final (error, trace) = await _applyInterceptors();
if (error != null) { if (error != null) {
_sendError(error); _sendError(error, trace);
_sinkIncoming(); _sinkIncoming();
return; return;
} }
@ -194,31 +194,31 @@ class ServerHandler extends ServiceCall {
_startStreamingRequest(); _startStreamingRequest();
} }
GrpcError? _onMetadata() { (GrpcError?, StackTrace?) _onMetadata() {
try { try {
_service.$onMetadata(this); _service.$onMetadata(this);
} on GrpcError catch (error) { } on GrpcError catch (error, trace) {
return error; return (error, trace);
} catch (error) { } catch (error, trace) {
final grpcError = GrpcError.internal(error.toString()); final grpcError = GrpcError.internal(error.toString());
return grpcError; return (grpcError, trace);
} }
return null; return (null, null);
} }
Future<GrpcError?> _applyInterceptors() async { Future<(GrpcError?, StackTrace?)> _applyInterceptors() async {
try { try {
for (final interceptor in _interceptors) { for (final interceptor in _interceptors) {
final error = await interceptor(this, _descriptor); final error = await interceptor(this, _descriptor);
if (error != null) { if (error != null) {
return error; return (error, null);
} }
} }
} catch (error) { } catch (error, trace) {
final grpcError = GrpcError.internal(error.toString()); final grpcError = GrpcError.internal(error.toString());
return grpcError; return (grpcError, trace);
} }
return null; return (null, null);
} }
void _startStreamingRequest() { void _startStreamingRequest() {
@ -226,14 +226,14 @@ class ServerHandler extends ServiceCall {
_requests = requests; _requests = requests;
_incomingSubscription!.onData(_onDataActive); _incomingSubscription!.onData(_onDataActive);
final error = _onMetadata(); final (error, trace) = _onMetadata();
if (error != null) { if (error != null) {
if (!requests.isClosed) { if (!requests.isClosed) {
requests requests
..addError(error) ..addError(error)
..close(); ..close();
} }
_sendError(error); _sendError(error, trace);
_onDone(); _onDone();
_stream.terminate(); _stream.terminate();
return; return;