Enhancements to the Result Pattern Documentation #11606
Labels
co.request
Community ask for documentation
e2-days
Effort: < 5 days
from.page-issue
Reported in a reader-filed concern
p2-medium
Necessary but not urgent concern. Resolve when possible.
Page URL
https://docs.flutter.dev/app-architecture/design-patterns/result#using-the-result-pattern
Page source
No response
Describe the problem
The Result class is useful for encapsulating success and error outcomes. However, it has some undocumented limitations.
Loss of Stack Traces:
The
Error
class only stores theException
object but not the associatedStackTrace
. Without the stack trace, debugging becomes more difficult and you don't get the most out of services like Crashlytics.Loss of Centralized Error Handling
Developers relying on FlutterError.onError as their centralised error-handling mechanism, may not realise that errors wrapped in
Result
instances are excluded unless they explicitly log them.Lack of Documentation:
There is no guidance on handling this effectively whilst using this pattern, which could lead to suppressed exceptions or silent failures.
Expected fix
Enhance the Error Class:
Add a StackTrace field to preserve this information:
Update Documentation:
Include best practices for:
Handling
Error
cases (e.g., logging or rethrowing exceptions).Preserving
StackTrace
s for debugging.Show How to Report to Crash Reporting Solutions:
Show how developers can bridge the gap between the Result class and FlutterError.onError to ensure exceptions are still reported.
For example:
Additional context
No response
I would like to fix this problem.
The text was updated successfully, but these errors were encountered: