Skip to content

Commit

Permalink
fix(frontend): fix error handling for test specs (#2420)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeepc committed Apr 21, 2023
1 parent 3980f16 commit 6fdb92d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion web/src/components/TestSpecDetail/Assertion.tsx
@@ -1,4 +1,5 @@
import AttributeValue from 'components/AttributeValue';
import AssertionService from 'services/Assertion.service';
import OperatorService from 'services/Operator.service';
import {ICheckResult} from 'types/Assertion.types';
import {TCompareOperatorSymbol} from 'types/Operator.types';
Expand All @@ -16,7 +17,7 @@ interface IProps {
const Assertion = ({check, testId, runId, selector}: IProps) => (
<S.CheckItemContainer>
<S.GridContainer>
{check.result.error ? (
{check.result.error && AssertionService.isValidError(check.result.error) ? (
<>
<S.Row $justify="center">
<S.IconWarning />
Expand Down
2 changes: 2 additions & 0 deletions web/src/constants/TestSpecs.constants.ts
Expand Up @@ -82,3 +82,5 @@ export const TEST_SPEC_SNIPPETS: TSnippet[] = [
DB_SPANS_RESPONSE_TIME,
DB_SPANS_QUALITY_DB_STATEMENT_PRESENT,
];

export const TestSpecErrors = ['resolution error', 'invalid syntax'];
15 changes: 11 additions & 4 deletions web/src/services/Assertion.service.ts
@@ -1,13 +1,14 @@
import countBy from 'lodash/countBy';
import uniq from 'lodash/uniq';

import {ICheckResult, TStructuredAssertion} from 'types/Assertion.types';
import {durationRegExp} from 'constants/Common.constants';
import {Attributes} from 'constants/SpanAttribute.constants';
import {CompareOperatorSymbolMap, OperatorRegexp} from 'constants/Operator.constants';
import {Attributes} from 'constants/SpanAttribute.constants';
import {TestSpecErrors} from 'constants/TestSpecs.constants';
import AssertionResult, {TRawAssertionResult} from 'models/AssertionResult.model';
import {ICheckResult, TStructuredAssertion} from 'types/Assertion.types';
import {TCompareOperatorSymbol} from 'types/Operator.types';
import {isJson} from 'utils/Common';
import AssertionResult, {TRawAssertionResult} from 'models/AssertionResult.model';

const isNumeric = (num: string): boolean => /^-?\d+(?:\.\d+)?$/.test(num);
const isNumericTime = (num: string): boolean => durationRegExp.test(num);
Expand Down Expand Up @@ -42,8 +43,14 @@ const AssertionService = () => ({
return countBy(passedResults);
},

isValidError(error: string) {
return TestSpecErrors.some(testSpecError => error.includes(testSpecError));
},

hasError(resultList: AssertionResult[]) {
return resultList.map(({spanResults}) => spanResults.some(({error}) => !!error)).some(result => !!result);
return resultList
.map(({spanResults}) => spanResults.some(({error}) => !!error && this.isValidError(error)))
.some(result => !!result);
},

getResultsHashedBySpanId(resultList: AssertionResult[]) {
Expand Down

0 comments on commit 6fdb92d

Please sign in to comment.