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 error handling #1465

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/components/MiniWidgetInstantiator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script setup lang="ts">
import { type AsyncComponentLoader, defineAsyncComponent, toRefs } from 'vue'

import type { MiniWidget, MiniWidgetType } from '@/types/widgets'
import { type MiniWidget, MiniWidgetType } from '@/types/widgets'

const props = defineProps<{
/**
Expand All @@ -19,10 +19,19 @@ const miniWidget = toRefs(props).miniWidget
const componentCache: Record<string, AsyncComponentLoader> = {}

const componentFromType = (componentType: MiniWidgetType): AsyncComponentLoader => {
if (!Object.values(MiniWidgetType).includes(componentType)) {
console.error(`Trying to import mini-widget with unknown '${componentType}' type. Import aborted.`)
return
}

if (componentCache[componentType] === undefined) {
componentCache[componentType] = defineAsyncComponent(
() => import(`../components/mini-widgets/${componentType}.vue`)
)
try {
componentCache[componentType] = defineAsyncComponent(
() => import(`../components/mini-widgets/${componentType}.vue`)
)
} catch (error) {
console.error(`Failed to load mini-widget component: ${componentType}`, error)
}
}

return componentCache[componentType]
Expand Down
19 changes: 14 additions & 5 deletions src/stores/mainVehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,15 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
updateVehicleId()

setInterval(async () => {
const blueosStatus = await getStatus(globalAddress.value)
// If blueos is not available, do not try to get data from it
if (!blueosStatus) return
try {
const blueosStatus = await getStatus(globalAddress.value)
if (!blueosStatus) {
throw new Error('BlueOS is not available.')
}
} catch (error) {
console.error(error)
return
}

const blueosVariablesAddresses = {
cpuTemp: 'blueos/cpu/tempC',
Expand All @@ -465,9 +471,12 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => {
})

if (usedGenericVariables.value.includes(blueosVariablesAddresses.cpuTemp)) {
getCpuTempCelsius(globalAddress.value).then((temp) => {
try {
const temp = await getCpuTempCelsius(globalAddress.value)
Object.assign(genericVariables, { ...genericVariables, ...{ [blueosVariablesAddresses.cpuTemp]: temp } })
})
} catch (error) {
console.error(error)
}
}
}, 1000)

Expand Down