Skip to content

Commit

Permalink
feat(client): Capture stack traces in UnknownExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
shyndman authored and micimize committed May 25, 2021
1 parent 26bb939 commit 4b36c09
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
22 changes: 11 additions & 11 deletions packages/graphql/lib/src/core/query_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ class QueryManager {
response,
queryResult,
);
} catch (failure) {
} catch (failure, trace) {
// we set the source to indicate where the source of failure
queryResult ??= QueryResult(source: QueryResultSource.network);

queryResult.exception = coalesceErrors(
exception: queryResult.exception,
linkException: translateFailure(failure),
linkException: translateFailure(failure, trace),
);
}

Expand All @@ -118,10 +118,10 @@ class QueryManager {

return queryResult;
}).transform(StreamTransformer.fromHandlers(
handleError: (err, trace, sink) => sink.add(_wrapFailure(err)),
handleError: (err, trace, sink) => sink.add(_wrapFailure(err, trace)),
));
} catch (ex) {
yield* Stream.fromIterable([_wrapFailure(ex)]);
} catch (ex, trace) {
yield* Stream.fromIterable([_wrapFailure(ex, trace)]);
}
}

Expand Down Expand Up @@ -218,13 +218,13 @@ class QueryManager {
response,
queryResult,
);
} catch (failure) {
} catch (failure, trace) {
// we set the source to indicate where the source of failure
queryResult ??= QueryResult(source: QueryResultSource.network);

queryResult.exception = coalesceErrors(
exception: queryResult.exception,
linkException: translateFailure(failure),
linkException: translateFailure(failure, trace),
);
}

Expand Down Expand Up @@ -288,10 +288,10 @@ class QueryManager {
);
}
}
} catch (failure) {
} catch (failure, trace) {
queryResult.exception = coalesceErrors(
exception: queryResult.exception,
linkException: translateFailure(failure),
linkException: translateFailure(failure, trace),
);
}

Expand Down Expand Up @@ -504,8 +504,8 @@ class QueryManager {
}
}

QueryResult _wrapFailure(dynamic ex) => QueryResult(
QueryResult _wrapFailure(dynamic ex, trace) => QueryResult(
// we set the source to indicate where the source of failure
source: QueryResultSource.network,
exception: coalesceErrors(linkException: translateFailure(ex)),
exception: coalesceErrors(linkException: translateFailure(ex, trace)),
);
5 changes: 3 additions & 2 deletions packages/graphql/lib/src/exceptions/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import 'package:graphql/src/exceptions/network.dart'
export 'package:graphql/src/exceptions/network.dart'
if (dart.library.io) 'package:graphql/src/exceptions/network_io.dart';

LinkException translateFailure(dynamic failure) {
LinkException translateFailure(dynamic failure, StackTrace trace) {
if (failure is LinkException) {
return failure;
}
return network.translateFailure(failure) ?? UnknownException(failure);
return network.translateFailure(failure) ??
UnknownException(failure, trace);
}
6 changes: 5 additions & 1 deletion packages/graphql/lib/src/exceptions/exceptions_next.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,16 @@ class UnexpectedResponseStructureException extends ServerException
class UnknownException extends LinkException {
String get message => 'Unhandled Client-Side Exception: $originalException';

final StackTrace originalStackTrace;

const UnknownException(
dynamic originalException,
this.originalStackTrace,
) : super(originalException);

@override
String toString() => "UnknownException($originalException)";
String toString() =>
"UnknownException($originalException, stack:\n$originalStackTrace\n)";
}

/// Container for both [graphqlErrors] returned from the server
Expand Down

0 comments on commit 4b36c09

Please sign in to comment.