Skip to content

Commit

Permalink
fix(frontend): Don't crash on color retrieval error (#24780)
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes authored Sep 4, 2024
1 parent 74420aa commit e26da47
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion frontend/src/lib/colors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { captureException } from '@sentry/react'

import { LifecycleToggle } from '~/types'

import { LemonTagType } from './lemon-ui/LemonTag'
Expand Down Expand Up @@ -39,7 +41,9 @@ export const tagColors: LemonTagType[] = [
export function getColorVar(variable: string): string {
const colorValue = getComputedStyle(document.body).getPropertyValue('--' + variable)
if (!colorValue) {
throw new Error(`Couldn't find color variable --${variable}`)
captureException(new Error(`Couldn't find color variable --${variable}`))
// Fall back to black or white depending on the theme
return document.body.getAttribute('theme') === 'light' ? '#000' : '#fff'
}
return colorValue.trim()
}
Expand Down

0 comments on commit e26da47

Please sign in to comment.