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

fix(connect): FW revision check offline handling #15664

Closed
wants to merge 1 commit into from

Conversation

Lemonexe
Copy link
Contributor

@Lemonexe Lemonexe commented Dec 2, 2024

Description

Fix handling of fetch errors when FW revision check encounters version not known locally.

You can test locally with user env 1-main | 2-main and turning off Wi-Fi.
Or you can start a released emulator and delete the corresponding entry from releases.json, and try it with Wi-Fi on/off.

Screenshots:

Before:
other error

After:
offline error

@@ -87,7 +95,7 @@ export const checkFirmwareRevision = async ({

return { success: true };
} catch (e) {
if (e.name === 'FetchError' && e.code === 'ENOTFOUND') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This catches only when network adapter is on, but there is no response or 4xx or 5xx response from server.
This did not catch error when network adapter is off. And that's is not an edge case - laptop/mobile users can routinely toggle Wi-Fi to save battery power...
Handling it in getOnlineReleaseMetadata makes sure we catch any fetch error, while still distinguishing from other-error in main function body.

@Lemonexe Lemonexe marked this pull request as ready for review December 2, 2024 10:12
isEqual(onlineRelease.version, firmwareVersion),
);
} catch {
throw OFFLINE_ERROR;
Copy link
Contributor

Choose a reason for hiding this comment

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

This will hide original error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I do not really like throwing something what is not the exception (in JS the Error)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original implementation did not use the error either 🤷
It only reported failFirmwareRevisionCheck('other-error') or failFirmwareRevisionCheck('cannot-perform-check-offline')

Copy link
Contributor

@komret komret left a comment

Choose a reason for hiding this comment

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

Great innitiative, but unfortunately, it reintroduces the bug I attempted to fix in #14626.

I reproduced it by using a T3B1 device, removing 2.8.3 from releases.json, and changing the URL to https://raw.githubusercontent.com/trezor/data/d704edf1dfff1fe97226af706ac8eff6291c6bb8/firmware/t3b1/releases.json` - this leads to a JSON which cannot be parsed.

As a result, I see this banner despite being online:
Screenshot 2024-12-02 at 12 45 58
Screenshot 2024-12-02 at 13 00 00

@Lemonexe Lemonexe marked this pull request as draft December 2, 2024 12:10
@Lemonexe
Copy link
Contributor Author

Lemonexe commented Dec 2, 2024

Great innitiative, but unfortunately, it reintroduces the bug I attempted to fix in #14626.

I reproduced it by using a T3B1 device, removing 2.8.3 from releases.json, and changing the URL to https://raw.githubusercontent.com/trezor/data/d704edf1dfff1fe97226af706ac8eff6291c6bb8/firmware/t3b1/releases.json` - this leads to a JSON which cannot be parsed.

Right. Meanwhile I also noticed when looking into the failing unit test, that the current behavior was done intentionally.
I'm closing this and I'll make a PR that only adds condition to check for the specific error when network adapter is off

@Lemonexe Lemonexe closed this Dec 2, 2024
@Lemonexe Lemonexe deleted the fix/fw-revision-check-offline-handling branch December 2, 2024 12:15
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.

3 participants