-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(detectors): Safely access queryObj for cron monitors #119444
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,15 +52,16 @@ import {selectCheckInData} from 'sentry/views/insights/crons/utils/selectCheckIn | |
| import {useMonitorStats} from 'sentry/views/insights/crons/utils/useMonitorStats'; | ||
|
|
||
| function VisualizationCell({detector}: {detector: CronDetector}) { | ||
| const cronId = detector.dataSources[0].queryObj.id; | ||
| const cronEnvironments = detector.dataSources[0].queryObj.environments; | ||
| const queryObj = detector.dataSources[0]?.queryObj; | ||
| const cronId = queryObj?.id; | ||
| const cronEnvironments = queryObj?.environments; | ||
|
|
||
| const elementRef = useRef<HTMLDivElement>(null); | ||
| const {width: containerWidth} = useDimensions({elementRef}); | ||
| const timelineWidth = useDebouncedValue(containerWidth, 1000); | ||
| const timeWindowConfig = useTimeWindowConfig({timelineWidth}); | ||
| const {data: monitorStats, isPending} = useMonitorStats({ | ||
| monitors: [detector.dataSources[0].queryObj.id], | ||
| monitors: cronId ? [cronId] : [], | ||
| timeWindowConfig, | ||
| }); | ||
|
|
||
|
|
@@ -72,7 +73,7 @@ function VisualizationCell({detector}: {detector: CronDetector}) { | |
| height="100%" | ||
| > | ||
| <Stack gap="sm" width="100%" ref={elementRef}> | ||
| {cronEnvironments.map(environment => { | ||
| {cronEnvironments?.map(environment => { | ||
| if (isPending) { | ||
| return <CheckInPlaceholder key={environment.name} />; | ||
| } | ||
|
|
@@ -108,7 +109,7 @@ const ADDITIONAL_COLUMNS: MonitorListAdditionalColumn[] = [ | |
| return ( | ||
| <SimpleTable.RowCell data-column-name="environment-label" alignSelf="start"> | ||
| <Stack gap="sm" width="100%"> | ||
| {detector.dataSources[0].queryObj.environments.map(environment => { | ||
| {detector.dataSources[0]?.queryObj?.environments.map(environment => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Incomplete optional chaining on Suggested FixAdd optional chaining before the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| return ( | ||
| <Text density="compressed" key={environment.name}> | ||
| <MonitorEnvironmentLabel | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe map on environments
High Severity
When
queryObjis null, optional chaining yieldsundefinedforenvironments, but.mapis still invoked on that value. That throws the same class of runtime error this PR targets, so the environment column can still crash for cron detectors without aqueryObj.Reviewed by Cursor Bugbot for commit c6ddf6d. Configure here.