Requiring data preserves the stackTrace (#93592)
This commit is contained in:
parent
af9cf734e8
commit
e05ddcbd9e
@ -249,7 +249,7 @@ class AsyncSnapshot<T> {
|
||||
if (hasData)
|
||||
return data!;
|
||||
if (hasError)
|
||||
throw error!; // ignore: only_throw_errors, since we're just propagating an existing error
|
||||
Error.throwWithStackTrace(error!, stackTrace!);
|
||||
throw StateError('Snapshot has neither data nor error');
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,20 @@ void main() {
|
||||
return Text(snapshot.toString(), textDirection: TextDirection.ltr);
|
||||
}
|
||||
group('AsyncSnapshot', () {
|
||||
test('requiring data preserves the stackTrace', () {
|
||||
final StackTrace originalStackTrace = StackTrace.current;
|
||||
|
||||
try {
|
||||
AsyncSnapshot<String>.withError(
|
||||
ConnectionState.done,
|
||||
Error(),
|
||||
originalStackTrace,
|
||||
).requireData;
|
||||
fail('requireData did not throw');
|
||||
} catch (error, stackTrace) {
|
||||
expect(stackTrace, originalStackTrace);
|
||||
}
|
||||
});
|
||||
test('requiring data succeeds if data is present', () {
|
||||
expect(
|
||||
const AsyncSnapshot<String>.withData(ConnectionState.done, 'hello').requireData,
|
||||
|
Loading…
x
Reference in New Issue
Block a user