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

Improve DioErrors #1405

Closed
wants to merge 49 commits into from
Closed

Improve DioErrors #1405

wants to merge 49 commits into from

Conversation

ueman
Copy link
Contributor

@ueman ueman commented Jan 26, 2022

NOTE: This goes against the develop-5.0 branch, since it's a breaking change.

New Pull Request Checklist

  • I have read the Documentation
  • I have searched for a similar pull request in the project and found none
  • I have updated this branch with the latest develop to avoid conflicts (via merge from master or rebase)
  • I have added the required tests to prove the fix/feature I am adding
  • I have updated the documentation (if necessary)
  • I have run the tests and they pass

Pull Request Description

This significantly improves the inner stacktraces of the DioError.

@ueman ueman marked this pull request as draft January 26, 2022 15:09
@jgoyvaerts
Copy link
Contributor

Good idea! Can you include an example of a stacktrace message before and after your PR so people can see the difference?

@ueman
Copy link
Contributor Author

ueman commented Jan 26, 2022

Good idea! Can you include an example of a stacktrace message before and after your PR so people can see the difference?

I'm still thinking about how to produce those cases, in order to test it. Do you have any ideas?

@ueman ueman changed the title Improve inner stacktraces of DioError Improve DioErrors Jan 27, 2022
@kuhnroyal
Copy link
Member

Just a reminder too myself: Consider raising to Dart 2.16 and using Error.rethrowWithStackTrace.

@ueman
Copy link
Contributor Author

ueman commented Jan 30, 2022

@kuhnroyal Do you mind sharing your test cases? Then I can go through them.

@kuhnroyal
Copy link
Member

It's nothing special, I only tested:

  1. 404 response from a random URL (this has no inner error as the response is received)
  2. Something like post<void>(url, data: ArgumentError()) - this throws a serialization error an has an inner error/stacktrace

Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ueman. The change looks valid overall, with only a few nit-pickings.

Also, there are a few things I'm considering:

  • Are you willing to contribute by letting us pick the PR to another community-maintained dio? (We'll announce the new repo later once we merge PRs as much as possible.)
  • It might be better to add some tests.
  • .DS_Store can be removed from the PR.

dio/lib/src/adapters/browser_adapter.dart Outdated Show resolved Hide resolved
dio/lib/src/adapters/io_adapter.dart Outdated Show resolved Hide resolved
/// It occurs when url is opened timeout.
connectTimeout,
/// Caused by a connection timeout.
connectionTimeout,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes with DioErrorType should be considered as a breaking change, which means you'll need to update the migration guide?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a breaking change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I need to add anything to the migration guide. From a user's point of view, nothing changes. The user can still catch exceptions the same way as before. All breaking changes are done from within the package in this PR.

@ueman
Copy link
Contributor Author

ueman commented Oct 19, 2022

Hi @ueman. The change looks valid overall, with only a few nit-pickings.

Also, there are a few things I'm considering:

  • Are you willing to contribute by letting us pick the PR to another community-maintained dio? (We'll announce the new repo later once we merge PRs as much as possible.)

Sure.

  • It might be better to add some tests.

I agree, any specific suggestions for tests? Just so I don't miss anything, you might think is important.

  • .DS_Store can be removed from the PR.

Yes, good point

@AlexV525
Copy link
Member

Sure.

Thanks!

I agree, any specific suggestions for tests? Just so I don't miss anything, you might think is important.

IMO tests should be covered by checking if requests throw corresponding exceptions in condition.

ueman and others added 4 commits October 21, 2022 19:36
# Conflicts:
#	dio/CHANGELOG.md
#	dio/lib/src/adapters/io_adapter.dart
#	dio/lib/src/options.dart
Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we've already merged a couple PRs in the fork, I would suggest that we can submit this PR to the fork directly.

@@ -630,6 +636,11 @@ abstract class DioMixin implements Dio {
}
}

StackTrace? stackTrace;
if (maybeStackTrace is StackTrace?) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybeStackTrace will always be StackTrace. The condition can be maybeStackTrace != StackTrace.empty.


# 4.0.5-beta1
- Add option to instantiate a `HttpClientAdapter`, which is platform independent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we need to change the base branch to develop.

StackTrace.current,
);
xhr.abort();
if (haveSent) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be fix by another PR.


/// When the request is cancelled, dio will throw a error with this type.
cancel,
requestCancelled,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users usually ignore canceled requests since they are meant to do it, which means they'll rely on the en. Maybe we can keep the naming at least for the least breaking.

Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would now suggest submitting the PR to the fork directly. Also, the target branch should be main.

@ueman
Copy link
Contributor Author

ueman commented Nov 3, 2022

I would now suggest submitting the PR to the fork directly. Also, the target branch should be main.

I don't have the permissions to do that

@AlexV525
Copy link
Member

AlexV525 commented Nov 3, 2022

I don't have the permissions to do that

Sorry. It should be granted now.

@AlexV525
Copy link
Member

Hi everyone! We've made our hardfork repo public and published a new version of dio, named diox.
The new package contains the PR of the fix.
Please refer to https://pub.dev/packages/diox/versions/5.0.0-dev.1 to use the fork.
You can also see why we're working for a hardfork at cfug/diox#29 and #1607.

@AlexV525 AlexV525 closed this Feb 13, 2023
@kuhnroyal
Copy link
Member

I am missing a lot of stacktraces in DioErrors after this change.
This was merged in the diox repository.

@kuhnroyal
Copy link
Member

All the server response errors have no stackTrace at all. It is impossible to tell where the error originated.

AlexV525 added a commit that referenced this pull request Mar 27, 2023
[Improve nullability in
DioMixin.assureResponse](8418c72)
* there should never be a case where there are not `RequestOptions`
available
* this is technically a breaking change but we should instead mark this
`@internal` in the future

[Fix missing source stacktrace in
DioError](4f4ffe4)

* a `DioError` should always have a meaningful stacktrace which points
to the actual invocation of `Dio.get/post/xxx`
* `Dio` historically lost a lot of this source information due to a
multitude of asynchronous calls
* now the source stacktrace is consistently being set into the
`RequestOptions` instance and can later be retrieved and used when a
`DioError` is constructed
* additionally a `DioError` may contain another cause which may itself
contain a separate stackTrace with more detailed information


### New Pull Request Checklist

- [x] I have read the
[Documentation](https://pub.dev/documentation/dio/latest/)
- [x] I have searched for a similar pull request in the
[project](https://github.com/cfug/dio/pulls) and found none
- [x] I have updated this branch with the latest `main` branch to avoid
conflicts (via merge from master or rebase)
- [x] I have added the required tests to prove the fix/feature I'm
adding
- [x] I have updated the documentation (if necessary)
- [x] I have run the tests without failures
- [x] I have updated the `CHANGELOG.md` in the corresponding package

### Additional context and info (if any)

The existing behavior which was somewhat correct got lost in
#1405 which was merged in the temporary
diox repository.

---------

Signed-off-by: Alex Li <[email protected]>
Co-authored-by: Alex Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet