mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 13:08:01 +00:00
[cfe] Ensure Crash.trace is printed when Crash is created directly
The Crash class was used for to conflicting purposes: 1) To encapsulate a captured crash in the CFE, in which case the trace was printed directly, and 2) To propagate a crash in the CFE together with the context in which it crash, in which case the trace was not printed but just included in the Crash object. This CL adds a `_hasBeenReported` field to ensure that 1) is rethrown as intended and 2) is printed and a Crash object of type 1) is returned. Change-Id: I6efc752414158aad60867b5dbb8d799d5b08036a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262420 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
2a43b37898
commit
b16e2aea54
|
@ -32,6 +32,8 @@ class Crash {
|
|||
|
||||
final StackTrace? trace;
|
||||
|
||||
bool _hasBeenReported = false;
|
||||
|
||||
Crash(this.uri, this.charOffset, this.error, this.trace);
|
||||
|
||||
@override
|
||||
|
@ -70,6 +72,7 @@ Future<T> reportCrash<T>(error, StackTrace trace,
|
|||
trace = error.trace ?? trace;
|
||||
uri = error.uri ?? uri;
|
||||
charOffset = error.charOffset ?? charOffset;
|
||||
error._hasBeenReported = true;
|
||||
error = error.error;
|
||||
}
|
||||
uri ??= firstSourceUri;
|
||||
|
@ -92,7 +95,8 @@ Future<T> reportCrash<T>(error, StackTrace trace,
|
|||
// Assume the crash logger isn't running.
|
||||
client.close(force: true);
|
||||
return new Future<T>.error(
|
||||
new Crash(uri, charOffset, error, trace), trace);
|
||||
new Crash(uri, charOffset, error, trace).._hasBeenReported = true,
|
||||
trace);
|
||||
}
|
||||
// ignore: unnecessary_null_comparison
|
||||
if (request != null) {
|
||||
|
@ -130,11 +134,12 @@ Future<T> withCrashReporting<T>(
|
|||
resetCrashReporting();
|
||||
try {
|
||||
return await action();
|
||||
} on Crash {
|
||||
rethrow;
|
||||
} on DebugAbort {
|
||||
rethrow;
|
||||
} catch (e, s) {
|
||||
if (e is Crash && e._hasBeenReported) {
|
||||
rethrow;
|
||||
}
|
||||
UriOffset? uriOffset = currentUriOffset();
|
||||
return reportCrash(e, s, uriOffset?.uri, uriOffset?.fileOffset);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue