riverpod
riverpod copied to clipboard
Replace `StateError` with `ProviderMissingLastValueError` when disposing a provider with no value emitted
Related Issues
Working towards https://github.com/rrousselGit/riverpod/discussions/3223
Throwing an error would be acceptable, but users have to write hard-coded strings to match and escape:
void handleExceptions(Object error) {
if (error case final StateError error when error.message.contains('was disposed during loading state, yet no value could be emitted.') {
// ignore
return;
}
}
The PR adds ProviderMissingLastValueError so the error could be gracefully caught and handled specifically.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
-
[x] I have updated the
CHANGELOG.mdof the relevant packages. Changelog files must be edited under the form:## Unreleased fix/major/minor - Description of your change. (thanks to @yourGithubId) -
[ ] If this contains new features or behavior changes, I have updated the documentation to match those changes.
Summary by CodeRabbit
Summary by CodeRabbit
-
Bug Fixes
- Improved error reporting when disposing a provider that has not emitted any value. The error type is now more specific, making it easier to identify and understand this scenario.
-
Documentation
- Updated changelog to reflect the new error type for provider disposal without emitted values.
-
Tests
- Updated tests to expect the new, more specific error type when a provider is disposed before emitting a value.
Walkthrough
This change introduces a new error class, ProviderMissingLastValueError, to replace the generic StateError when disposing a provider that never emitted a value. The changelog is updated, the error handling in the provider core is refactored, and related tests are updated to expect the new error type.
Changes
| File(s) | Change Summary |
|---|---|
| packages/riverpod/CHANGELOG.md | Added entry describing the new ProviderMissingLastValueError for providers disposed without a value. |
| packages/riverpod/lib/src/core/element.dart | Removed private _missingLastValueError, added ProviderMissingLastValueError class, updated usage. |
| packages/riverpod/test/old/legacy_providers/stream_provider/stream_provider_test.dart | Updated test to expect ProviderMissingLastValueError instead of generic StateError. |
Possibly related PRs
- rrousselGit/riverpod#4150: Introduced the
ElementWithFuturemixin with async state management; this PR refactors error handling within that mixin by replacing a private error method with a dedicated error class.
Suggested reviewers
- rrousselGit
Poem
In the garden of code, a new error does bloom,
No more generic shadows, specificity resumes!
Providers now whisper, with clarity they cry,
"Missing last value!"—a truth you can't deny.
The river flows onward, with type-safety in view,
🐇✨ Here’s to precise errors—cheers to something new!
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between c812128d5984ea7f6024175be0117009d4665bc8 and 5480cc7a5bb6451b9486713847c3b59b809e536f.
📒 Files selected for processing (2)
packages/riverpod/lib/src/core/element.dart(2 hunks)packages/riverpod/test/old/legacy_providers/stream_provider/stream_provider_test.dart(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/riverpod/lib/src/core/element.dart
- packages/riverpod/test/old/legacy_providers/stream_provider/stream_provider_test.dart
⏰ Context from checks skipped due to timeout of 90000ms (20)
- GitHub Check: build (master, packages/flutter_riverpod)
- GitHub Check: build (stable, packages/hooks_riverpod)
- GitHub Check: build (master, examples/counter)
- GitHub Check: build (stable, packages/riverpod/example)
- GitHub Check: build (stable, examples/pub)
- GitHub Check: build (stable, examples/stackoverflow)
- GitHub Check: build (stable, examples/marvel)
- GitHub Check: build (stable, examples/todos)
- GitHub Check: build (stable, examples/random_number)
- GitHub Check: build (stable, examples/counter)
- GitHub Check: riverpod_lint (stable, packages/riverpod_lint_flutter_test)
- GitHub Check: check_generation
- GitHub Check: riverpod_lint (master, packages/riverpod_analyzer_utils_tests)
- GitHub Check: riverpod_lint (stable, packages/riverpod_lint)
- GitHub Check: riverpod_lint (stable, packages/riverpod_analyzer_utils)
- GitHub Check: riverpod_lint (master, packages/riverpod_lint)
- GitHub Check: riverpod_lint (stable, packages/riverpod_analyzer_utils_tests)
- GitHub Check: riverpod_lint (master, packages/riverpod_analyzer_utils)
- GitHub Check: riverpod_lint (master, packages/riverpod_lint_flutter_test)
- GitHub Check: changelog
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Explain this complex logic.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Checks are failing for unrelated reasons.
Please make an issue first. I need to understand the use case
Created https://github.com/rrousselGit/riverpod/issues/4168
Closing while we first agree on how to solve https://github.com/rrousselGit/riverpod/issues/4168