Skip to content

Commit 63188d2

Browse files
authored
fix(aci): Avoid crashing page when queryObj is null (#94377)
I guess we have a few metric issues that are missing their snuba query. Avoids crashing page and displays query missing error
1 parent e805e47 commit 63188d2

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

static/app/types/workflowEngine/detectors.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface SnubaQueryDataSource extends BaseDataSource {
3232
snubaQuery: SnubaQuery;
3333
status: number;
3434
subscription: string;
35-
};
35+
} | null;
3636
type: 'snuba_query_subscription';
3737
}
3838

static/app/views/detectors/components/detailsPanel.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ interface DetailsPanelProps {
1212
}
1313

1414
function SnubaQueryDetails({dataSource}: {dataSource: SnubaQueryDataSource}) {
15+
if (!dataSource.queryObj) {
16+
return <Container>{t('Query not found.')}</Container>;
17+
}
18+
1519
return (
1620
<Container>
1721
<Flex direction="column" gap={space(0.5)}>

static/app/views/detectors/components/detectorLink.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ function DataSourceDetails({dataSource}: {dataSource: DataSource}) {
122122
const type = dataSource.type;
123123
switch (type) {
124124
case 'snuba_query_subscription':
125+
if (!dataSource.queryObj) {
126+
return <DetailItem>{t('Query not found.')}</DetailItem>;
127+
}
125128
return (
126129
<Fragment>
127130
<DetailItem>{dataSource.queryObj.snubaQuery.environment}</DetailItem>

static/app/views/detectors/detail.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ describe('DetectorDetails', function () {
1717
const ownerTeam = TeamFixture();
1818
const dataSource = SnubaQueryDataSourceFixture({
1919
queryObj: {
20-
...defaultDataSource.queryObj,
20+
...defaultDataSource.queryObj!,
2121
snubaQuery: {
22-
...defaultDataSource.queryObj.snubaQuery,
22+
...defaultDataSource.queryObj!.snubaQuery,
2323
query: 'test',
2424
environment: 'test-environment',
2525
},
@@ -65,10 +65,10 @@ describe('DetectorDetails', function () {
6565
await screen.findByRole('heading', {name: snubaQueryDetector.name})
6666
).toBeInTheDocument();
6767
// Displays the snuba query
68-
expect(screen.getByText(dataSource.queryObj.snubaQuery.query)).toBeInTheDocument();
68+
expect(screen.getByText(dataSource.queryObj!.snubaQuery.query)).toBeInTheDocument();
6969
// Displays the environment
7070
expect(
71-
screen.getByText(dataSource.queryObj.snubaQuery.environment!)
71+
screen.getByText(dataSource.queryObj!.snubaQuery.environment!)
7272
).toBeInTheDocument();
7373
// Displays the owner team
7474
expect(screen.getByText(`Assign to #${ownerTeam.slug}`)).toBeInTheDocument();

static/app/views/detectors/detail.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const priorities: Priority[] = [
4747

4848
function getDetectorEnvironment(detector: Detector) {
4949
return detector.dataSources?.find(ds => ds.type === 'snuba_query_subscription')
50-
?.queryObj.snubaQuery.environment;
50+
?.queryObj?.snubaQuery.environment;
5151
}
5252

5353
function AssignToTeam({teamId}: {teamId: string}) {

0 commit comments

Comments
 (0)