Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to the Result Pattern Documentation #11606

Open
1 task
luketg8 opened this issue Jan 19, 2025 · 0 comments
Open
1 task

Enhancements to the Result Pattern Documentation #11606

luketg8 opened this issue Jan 19, 2025 · 0 comments
Assignees
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.

Comments

@luketg8
Copy link

luketg8 commented Jan 19, 2025

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 the Exception object but not the associated StackTrace. 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:

class Error<T> extends Result<T> {
  final Exception exception;
  final StackTrace stackTrace;

  Error(this.exception, [this.stackTrace = StackTrace.current]);
}

Update Documentation:
Include best practices for:
Handling Error cases (e.g., logging or rethrowing exceptions).
Preserving StackTraces 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:

if (result is Error) {
  FlutterError.reportError(FlutterErrorDetails(
    exception: result.exception,
    stack: result.stackTrace,
  ));
}

Additional context

No response

I would like to fix this problem.

  • I will try and fix this problem on docs.flutter.dev.
@luketg8 luketg8 added the from.page-issue Reported in a reader-filed concern label Jan 19, 2025
@luketg8 luketg8 changed the title Add Stack Traces to Results Enhancements to the Result Pattern Documentation Jan 19, 2025
@sfshaza2 sfshaza2 added p2-medium Necessary but not urgent concern. Resolve when possible. e2-days Effort: < 5 days co.request Community ask for documentation labels Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

3 participants