-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat(uptime): Display assertion compilation errors in form #106922
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
Merged
jaydgoss
merged 3 commits into
master
from
jaygoss/new-700-display-complication-errors-for-uptime-assertion-fields
Jan 26, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
static/app/views/alerts/rules/uptime/assertionFormErrors.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import {mapAssertionFormErrors} from 'sentry/views/alerts/rules/uptime/assertionFormErrors'; | ||
|
|
||
| describe('mapAssertionFormErrors', () => { | ||
| it('returns null/undefined as-is', () => { | ||
| expect(mapAssertionFormErrors(null)).toBeNull(); | ||
| expect(mapAssertionFormErrors(undefined)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('passes through responses without assertion errors', () => { | ||
| const response = {url: ['Invalid URL']}; | ||
| expect(mapAssertionFormErrors(response)).toEqual({url: ['Invalid URL']}); | ||
| }); | ||
|
|
||
| it('handles direct assertion compilation errors (uptime alerts format)', () => { | ||
| const response = { | ||
| assertion: { | ||
| error: 'compilation_error', | ||
| details: 'Invalid JSON path expression: syntax error at position 5', | ||
| }, | ||
| }; | ||
|
|
||
| expect(mapAssertionFormErrors(response)).toEqual({ | ||
| assertion: [ | ||
| 'Compilation Error: Invalid JSON path expression: syntax error at position 5', | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| it('handles direct assertion serialization errors (uptime alerts format)', () => { | ||
| const response = { | ||
| assertion: { | ||
| error: 'serialization_error', | ||
| details: 'unknown variant `invalid_op`, expected one of `and`, `or`', | ||
| }, | ||
| }; | ||
|
|
||
| expect(mapAssertionFormErrors(response)).toEqual({ | ||
| assertion: [ | ||
| 'Serialization Error: unknown variant `invalid_op`, expected one of `and`, `or`', | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| it('handles nested assertion errors (detector forms format)', () => { | ||
| const response = { | ||
| dataSources: { | ||
| assertion: { | ||
| error: 'compilation_error', | ||
| details: | ||
| 'JSONPath Parser Error: --> 1:3\n |\n1 | $[oooooo\n | ^---\n |\n = expected selector', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| expect(mapAssertionFormErrors(response)).toEqual({ | ||
| assertion: [ | ||
| 'Compilation Error: JSONPath Parser Error: --> 1:3\n |\n1 | $[oooooo\n | ^---\n |\n = expected selector', | ||
| ], | ||
| }); | ||
| }); | ||
|
|
||
| it('preserves other dataSources fields when extracting assertion error', () => { | ||
| const response = { | ||
| dataSources: { | ||
| assertion: { | ||
| error: 'compilation_error', | ||
| details: 'Invalid expression', | ||
| }, | ||
| url: ['Invalid URL format'], | ||
| method: ['Method is required'], | ||
| }, | ||
| }; | ||
|
|
||
| expect(mapAssertionFormErrors(response)).toEqual({ | ||
| assertion: ['Compilation Error: Invalid expression'], | ||
| dataSources: { | ||
| url: ['Invalid URL format'], | ||
| method: ['Method is required'], | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('handles unknown error types with fallback title', () => { | ||
| const response = { | ||
| assertion: { | ||
| error: 'unknown_error_type', | ||
| details: 'Something went wrong', | ||
| }, | ||
| }; | ||
|
|
||
| expect(mapAssertionFormErrors(response)).toEqual({ | ||
| assertion: ['Validation Error: Something went wrong'], | ||
| }); | ||
| }); | ||
|
|
||
| it('does not modify assertion if already an array', () => { | ||
| const response = { | ||
| assertion: ['Already formatted error'], | ||
| }; | ||
|
|
||
| expect(mapAssertionFormErrors(response)).toEqual({ | ||
| assertion: ['Already formatted error'], | ||
| }); | ||
| }); | ||
| }); |
79 changes: 79 additions & 0 deletions
79
static/app/views/alerts/rules/uptime/assertionFormErrors.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import {t} from 'sentry/locale'; | ||
|
|
||
| /** | ||
| * Maps assertion error types to user-friendly titles. | ||
| */ | ||
| function getAssertionErrorTitle(errorType: string): string { | ||
| switch (errorType) { | ||
| case 'compilation_error': | ||
| return t('Compilation Error'); | ||
| case 'serialization_error': | ||
| return t('Serialization Error'); | ||
| default: | ||
| return t('Validation Error'); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Checks if an object is an assertion error with error type and details. | ||
| */ | ||
| function isAssertionError(obj: unknown): obj is {details: string; error: string} { | ||
| return ( | ||
| typeof obj === 'object' && | ||
| obj !== null && | ||
| !Array.isArray(obj) && | ||
| 'details' in obj && | ||
| 'error' in obj | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Formats an assertion error into a user-friendly message. | ||
| */ | ||
| function formatAssertionError(assertionError: { | ||
| details: string; | ||
| error: string; | ||
| }): string[] { | ||
| const title = getAssertionErrorTitle(assertionError.error); | ||
| return [`${title}: ${assertionError.details}`]; | ||
| } | ||
|
|
||
| /** | ||
| * Maps form errors from the API response format to the format expected by FormModel. | ||
| * | ||
| * Handles assertion errors in two formats: | ||
| * | ||
| * 1. Direct format (uptime alerts): | ||
| * {"assertion": {"error": "compilation_error", "details": "..."}} | ||
| * | ||
| * 2. Nested format (detector forms): | ||
| * {"dataSources": {"assertion": {"error": "compilation_error", "details": "..."}}} | ||
| * | ||
| * Both are transformed to: {"assertion": ["Compilation Error: <error details>"]} | ||
| */ | ||
| export function mapAssertionFormErrors(responseJson: any): any { | ||
| if (!responseJson) { | ||
| return responseJson; | ||
| } | ||
|
|
||
| const result = {...responseJson}; | ||
|
|
||
| // Handle direct assertion errors (uptime alerts endpoint) | ||
| if (isAssertionError(result.assertion)) { | ||
| result.assertion = formatAssertionError(result.assertion); | ||
| } | ||
|
|
||
| // Handle nested assertion errors (detector forms endpoint) | ||
| if (result.dataSources && isAssertionError(result.dataSources.assertion)) { | ||
| result.assertion = formatAssertionError(result.dataSources.assertion); | ||
| // Remove assertion from dataSources but preserve other fields | ||
| const {assertion: _, ...remainingDataSources} = result.dataSources; | ||
| if (Object.keys(remainingDataSources).length > 0) { | ||
| result.dataSources = remainingDataSources; | ||
| } else { | ||
| delete result.dataSources; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.