Guard optional event fields before calling trim in live-log paths.

Legacy decrypted events may omit mgk or wind fields; optional chaining prevents runtime crashes in course prefill and stats aggregation.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-31 21:29:42 +02:00
co-authored by Cursor
parent aa03573e1f
commit 0b2c1c22c6
2 changed files with 7 additions and 5 deletions
@@ -71,21 +71,21 @@ export async function loadLogbookEventSeries(logbookId: string): Promise<EventSe
time: event.time
}
if (event.windPressure.trim()) {
if (event.windPressure?.trim()) {
pressure.push({
...base,
summary: `${event.windPressure} hPa`
})
}
if (event.windDirection.trim() || event.windStrength.trim()) {
if (event.windDirection?.trim() || event.windStrength?.trim()) {
wind.push({
...base,
summary: [event.windDirection, event.windStrength].filter(Boolean).join(' ')
})
}
const code = event.remarks.trim()
const code = event.remarks?.trim() ?? ''
if (
code === LIVE_EVENT_CODES.MOTOR_START ||
code === LIVE_EVENT_CODES.MOTOR_STOP