Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
fixes #2425
  • Loading branch information
rrousselGit committed Mar 10, 2024
1 parent 439a606 commit 2e2791d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/riverpod/lib/src/core/ref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ extension $RefArg on Ref<Object?> {
class UnmountedRefException implements Exception {
@override

Check warning on line 14 in packages/riverpod/lib/src/core/ref.dart

View check run for this annotation

Codecov / codecov/patch

packages/riverpod/lib/src/core/ref.dart#L14

Added line #L14 was not covered by tests
String toString() {
return 'Cannot use a Ref after it has been disposed. '
' This typically happens when a provider rebuilt, but the previous "build" was still pending and is still performing operations.'
' It is generally fine to let this exception be thrown, as it will be caught and handled by Riverpod.';
return '''
Cannot use a Ref after it has been disposed. This typically happens if:
- A provider rebuilt, but the previous "build" was still pending and is still performing operations.
You should therefore either use `ref.onDispose` to cancel pending work, or
check `ref.mounted` after async gaps or anything that could invalidate the provider.
- You tried to use Ref inside `onDispose` or other life-cycles.
This is not supported, as the provider is already being disposed.
''';
}
}

Expand Down

0 comments on commit 2e2791d

Please sign in to comment.