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

Wrap all management service calls in Either #6500

Merged

Conversation

Pururun
Copy link
Contributor

@Pururun Pururun commented Jul 24, 2024

This is so the app will not crash if an error occured.

Added konsist test so that all calls needs to be wrapped in Either.


This change is Reviewable

@Pururun Pururun added the Android Issues related to Android label Jul 24, 2024
@Pururun Pururun requested a review from Rawa July 24, 2024 14:43
Copy link

linear bot commented Jul 24, 2024

Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r2, all commit messages.
Reviewable status: 5 of 9 files reviewed, 2 unresolved discussions (waiting on @Pururun)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 268 at r2 (raw file):

            .mapLeft(ConnectError::Unknown)

    suspend fun disconnect(): Either<ConnectError, Boolean> =

If we believe these can result in errors we should also handle them downstream, right now the new are kind of fail silent. We catch the error but we don't do anything with it. See code below, same goes for some of the others:

lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/ConnectionProxy.kt
23:    suspend fun disconnect() = managementService.disconnect()

android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ManagementServiceTest.kt line 10 at r2 (raw file):

class ManagementServiceTest {

    @Test

Nice test ⭐

@Pururun Pururun force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch 2 times, most recently from 3ecf40b to a53ae91 Compare July 31, 2024 12:11
Copy link
Contributor Author

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

Reviewable status: 4 of 19 files reviewed, 2 unresolved discussions (waiting on @Rawa)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 268 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

If we believe these can result in errors we should also handle them downstream, right now the new are kind of fail silent. We catch the error but we don't do anything with it. See code below, same goes for some of the others:

lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/ConnectionProxy.kt
23:    suspend fun disconnect() = managementService.disconnect()

Added toast messages for those that made sense and added logs for all calls.


android/test/arch/src/test/kotlin/net/mullvad/mullvadvpn/test/arch/ManagementServiceTest.kt line 10 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

Nice test ⭐

Done.

@Pururun Pururun requested a review from Rawa July 31, 2024 12:37
@Pururun Pururun force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch from f183eb8 to e8e8c4e Compare July 31, 2024 13:20
Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 4 files at r1, 14 of 14 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Pururun)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 268 at r2 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

Added toast messages for those that made sense and added logs for all calls.

Good, the logs will be critical because it will be the only way for us to debug from errors logs. Can we add error logs to every single case were we map to a Unknown error? This will help us expand the Unknown cases and introduce new well-typed errors in the future.

@Pururun Pururun force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch from e8e8c4e to ee4ece8 Compare August 6, 2024 09:28
Copy link
Contributor Author

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

Reviewable status: 19 of 20 files reviewed, 1 unresolved discussion (waiting on @Rawa)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 268 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

Good, the logs will be critical because it will be the only way for us to debug from errors logs. Can we add error logs to every single case were we map to a Unknown error? This will help us expand the Unknown cases and introduce new well-typed errors in the future.

Added logs for all unkown errors

Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewable status: 18 of 20 files reviewed, 1 unresolved discussion (waiting on @Pururun)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 268 at r2 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

Added logs for all unkown errors

Nice 👍 :lgtm:

Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r4.
Reviewable status: 19 of 20 files reviewed, all discussions resolved

Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r5.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@Pururun Pururun force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch from 2213c87 to 7aff65e Compare August 7, 2024 09:00
Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r6.
Reviewable status: 19 of 20 files reviewed, 3 unresolved discussions (waiting on @Pururun)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 331 at r6 (raw file):

                        LoginAccountError.MaxDevicesReached(accountNumber)
                    Status.Code.UNAVAILABLE -> LoginAccountError.RpcError
                    else -> LoginAccountError.Unknown(it)

Here too


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 531 at r6 (raw file):

                when (it.status.code) {
                    Status.Code.ALREADY_EXISTS -> NameAlreadyExists(customList.name)
                    else -> UnknownCustomListError(it)

We should log on this unknown case, so we can follow up on it.


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 625 at r6 (raw file):

                    Status.Code.RESOURCE_EXHAUSTED -> RedeemVoucherError.VoucherAlreadyUsed
                    Status.Code.UNAVAILABLE -> RedeemVoucherError.RpcError
                    else -> RedeemVoucherError.Unknown(it)

Same here

@Pururun Pururun force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch from 7aff65e to 3f518b7 Compare August 9, 2024 10:46
Rawa
Rawa previously approved these changes Aug 9, 2024
Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@Pururun Pururun force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch 2 times, most recently from e90a4ee to ba3b07f Compare August 9, 2024 14:12
@Pururun Pururun force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch from ba3b07f to a1016f2 Compare August 15, 2024 14:00
Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 4 files at r1, 3 of 5 files at r2, 12 of 14 files at r3, 1 of 1 files at r5, 1 of 1 files at r7, 1 of 38 files at r8, 37 of 37 files at r9, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @Pururun)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt line 179 at r9 (raw file):

                launch { copyToClipboard(sideEffect.accountNumber, copyTextString) }
            AccountViewModel.UiSideEffect.GenericError ->
                snackbarHostState.showSnackbarImmediately(message = errorString)

Is this new toast aligned with design? Same question applies to other new toasts


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 1 at r9 (raw file):

package net.mullvad.mullvadvpn.lib.daemon.grpc

Are we sure none of the new error logs contain any sensitive information when we include it? E.g. Logger.e("Disconnect error", it)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 716 at r9 (raw file):

    ): Either<TestApiAccessMethodError, Unit> =
        Either.catch { grpc.testCustomApiAccessMethod(customProxy.fromDomain()) }
            .onLeft { Logger.e("test custom api access method error", it) }

nit: Test

Code quote:

test

android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 726 at r9 (raw file):

    ): Either<TestApiAccessMethodError, Unit> =
        Either.catch { grpc.testApiAccessMethodById(apiAccessMethodId.fromDomain()) }
            .onLeft { Logger.e("test api access method error", it) }

nit: Test

Code quote:

tes

Copy link
Contributor Author

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @albin-mullvad)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 1 at r9 (raw file):

Previously, albin-mullvad wrote…

Are we sure none of the new error logs contain any sensitive information when we include it? E.g. Logger.e("Disconnect error", it)

If it is a grpc error it should not contain any sensitive information, but I guess it is possible if it is some other exception?

@Pururun Pururun force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch from a1016f2 to 4ec5380 Compare August 20, 2024 07:12
@albin-mullvad albin-mullvad requested a review from Rawa August 21, 2024 09:22
Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 3 files at r10, all commit messages.
Reviewable status: 56 of 57 files reviewed, 4 unresolved discussions (waiting on @Pururun and @Rawa)

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewable status: 56 of 57 files reviewed, 4 unresolved discussions (waiting on @Pururun and @Rawa)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 1 at r9 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

If it is a grpc error it should not contain any sensitive information, but I guess it is possible if it is some other exception?

If we can't be certain we should avoid including it. Can we make it more specific or skip it? Or perhaps use duplicate log calls: one Logger.e without it and one Logger.d with it (since the debug level wouldn't be included in release builds)

@Pururun Pururun force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch from 4ec5380 to 1dcad6a Compare August 22, 2024 08:54
Copy link
Contributor Author

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

Reviewable status: 50 of 57 files reviewed, 1 unresolved discussion (waiting on @albin-mullvad and @Rawa)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 1 at r9 (raw file):

Previously, albin-mullvad wrote…

If we can't be certain we should avoid including it. Can we make it more specific or skip it? Or perhaps use duplicate log calls: one Logger.e without it and one Logger.d with it (since the debug level wouldn't be included in release builds)

Removed all it

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewed 7 of 7 files at r11, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Pururun)


android/lib/daemon-grpc/src/main/kotlin/net/mullvad/mullvadvpn/lib/daemon/grpc/ManagementService.kt line 1 at r9 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

Removed all it

👍

@Pururun Pururun force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch from 1dcad6a to 5f40ec8 Compare August 22, 2024 13:27
Copy link
Contributor Author

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt line 179 at r9 (raw file):

Previously, albin-mullvad wrote…

Is this new toast aligned with design? Same question applies to other new toasts

It has now been aligned with design. Also created an issue in linear on how we can improve our handling of grpc failures.

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt line 179 at r9 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

It has now been aligned with design. Also created an issue in linear on how we can improve our handling of grpc failures.

Perfect! 🙌

@albin-mullvad albin-mullvad force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch from 5f40ec8 to cfe4996 Compare August 23, 2024 07:42
@albin-mullvad albin-mullvad force-pushed the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch from cfe4996 to 4c7a6fa Compare August 23, 2024 07:45
@albin-mullvad albin-mullvad merged commit 97ee66d into main Aug 23, 2024
28 checks passed
@albin-mullvad albin-mullvad deleted the ensure-all-potential-grpc-errors-are-wrapped-droid-1170 branch August 23, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issues related to Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants