From bab7bfd9b3e979579becdb99eb59770002a407d4 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Fri, 9 Aug 2024 16:58:24 -0700 Subject: [PATCH] settings-sync: Fix logic that updates unknown paths to keep trying on initial fail --- src/composables/settingsSyncer.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/composables/settingsSyncer.ts b/src/composables/settingsSyncer.ts index 1e7c9aa04..7df072d14 100644 --- a/src/composables/settingsSyncer.ts +++ b/src/composables/settingsSyncer.ts @@ -178,7 +178,7 @@ export function useBlueOsStorage(key: string, defaultValue: MaybeRef): Rem const message = `Fetched remote value of key ${key} from the vehicle.` openSnackbar({ message, duration: 3000, variant: 'success' }) } else { - updateValueOnBlueOS(currentValue.value) + await updateValueOnBlueOS(currentValue.value) const message = `Pushed local value of key ${key} to the vehicle.` openSnackbar({ message, duration: 3000, variant: 'success' }) } @@ -189,17 +189,25 @@ export function useBlueOsStorage(key: string, defaultValue: MaybeRef): Rem } catch (initialSyncError) { // If the initial sync fails because there's no value for the key on BlueOS, we can just use the current value if ((initialSyncError as Error).name === NoPathInBlueOsErrorName) { - console.debug(`No value for '${key}' on BlueOS. Using current value.`) - updateValueOnBlueOS(currentValue.value) - finishedInitialFetch.value = true - return + console.debug(`No value for '${key}' on BlueOS. Using current value. Will push it to BlueOS.`) + try { + await updateValueOnBlueOS(currentValue.value) + finishedInitialFetch.value = true + return + } catch (fetchError) { + console.error(`Not able to push current value of '${key}' to BlueOS. ${fetchError}`) + console.error(`Failed syncing '${key}' with BlueOS. Will keep trying.`) + + // If we can't update the value on BlueOS, try again in 10 seconds + initialSyncTimeout = setTimeout(tryToDoInitialSync, 10000) + return + } } // If the initial sync fails because we can't connect to BlueOS, try again in 10 seconds initialSyncTimeout = setTimeout(tryToDoInitialSync, 10000) - console.error(`Failed syncing '${key}' with BlueOS. Will keep trying.`) - console.error(`Not able to get current value of '${key}' on BlueOS. ${initialSyncError}`) + console.error(`Failed syncing '${key}' with BlueOS. Will keep trying. Error: ${initialSyncError}`) } }