-
Notifications
You must be signed in to change notification settings - Fork 115
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
🐛 Bug Report: Realtime.subscribe method doesn't dispatch any error if try to subscribe without connection. #131
Comments
@FernandoUFS thanks for creating this issue! 🙏🏼 I think this problem might be here: sdk-for-flutter/lib/src/realtime_mixin.dart Line 117 in f8480fd
If @lohanidamodar, what are your thoughts on how to proceed with this? |
may be an |
@lohanidamodar I could solve this issue by two ways. First way: The Second way: This line is the one causing the error when trying connecting without connection:
Using a try catch in that point we can send the error to the streams. But also it would be necessary send a success stream, so we can be sure that the connection was stablished. I tested with this code, and I could get the error in the realtimeSubscription stream try {
if (_websok == null) {
_websok = await getWebSocket(uri);
// Create a RealtimeMessage and send to the channels informing that the connection was success.
_lastUrl = uri.toString();
} else {
if (_lastUrl == uri.toString() && _websok?.closeCode == null) {
return;
}
await _closeConnection();
_lastUrl = uri.toString();
_websok = await getWebSocket(uri);
}
} catch (e) {
for (var list in _channels.values) {
for (var stream in list) {
stream.sink.addError(AppwriteException('Error connecting to server'));
}
}
} |
Thank you @FernandoUFS would you like to make a PR against https://github.com/appwrite/sdk-generator ? If not, no worries, we will look into it as well. |
Hi @lohanidamodar, as you can see, I was able to solve the problem in two ways, but I think the first way (the code in the repository) is more intuitive. However, this causes a breaking change, because now everyone will need to use |
Thank you @FernandoUFS yes, we would not want to break the interface as well as would want to keep it consistent with other SDKs. So giving back the error on onError for streams is the better option |
any update on this sir? |
👟 Reproduction steps
When using
realtime.subscribe
without connection it's not possible detect if it succeeded or failed, because the error of connection is not dispatched to outside of the sdk.The try catch is never fired nor the stream.onError nor the stream.onDone when trying to subscribe.
Example:
👍 Expected behavior
It should be possible to catch connection error and it should be possible to be sure that the connection was stablished.
When I say "to be sure that the connection was stablished" I mean that knowing if the stream had an error only solves one part of the problem. This is because I cannot be sure that the connection was successful simply by expecting not to receive an error.
Maybe the
subscribe
method being a Future I can know when the connection was stablished by awaiting.For instance:
👎 Actual Behavior
It actually never returns any errors in any way. The
onDone
function is only called if the connection was successfully established before and then the connection dies. However, if you try to subscribe without a connection, no error is dispatched.🎲 Appwrite version
Version 2.0.x
💻 Operating system
MacOS
🧱 Your Environment
flutter doctor
pubspec.yml
Device
👀 Have you spent some time to check if this issue has been raised before?
🏢 Have you read the Code of Conduct?
The text was updated successfully, but these errors were encountered: