Skip to content

Commit a3f1e67

Browse files
authored
Merge pull request #108 from buildingSMART/PJS003-Improve-Error-Message
PJS003 - Improve error message
2 parents 5cd379b + b00fbe5 commit a3f1e67

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

frontend/src/GherkinResult.js

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ import TablePagination from '@mui/material/TablePagination';
1414
import { statusToColor, severityToLabel, statusToLabel, severityToColor } from './mappings';
1515

1616
function unsafe_format(obj) {
17+
// PJS003 -> Invalid characters in GUID
18+
if (typeof obj == 'object' && 'invalid_guid_chars' in obj && 'expected_or_observed' in obj) {
19+
if (obj.expected_or_observed === 'expected') {
20+
return <span>{`One of the following characters: ${obj.invalid_guid_chars}`}</span>;
21+
} else if (obj.expected_or_observed === 'observed' && 'inst' in obj) {
22+
return (
23+
<span>
24+
{`For guid '${obj.inst}', the following invalid character(s) is/were found: ${obj.invalid_guid_chars}`}
25+
</span>
26+
);
27+
}
28+
}
29+
30+
// PJS003 -> invalid length
31+
if (typeof obj == 'object' && 'length' in obj && 'expected_or_observed' in obj) {
32+
if (obj.expected_or_observed === 'expected') {
33+
return <span>{`A sequence of length ${obj.length} for the global ID`}</span>;
34+
} else if (obj.expected_or_observed === 'observed' && 'inst' in obj) {
35+
return <span>{`The guid '${obj.inst}' is a sequence of length ${obj.length}`}</span>;
36+
}
37+
}
38+
1739
if (typeof obj == 'object' && 'value' in obj) {
1840
if (typeof obj.value === 'string' || obj.value instanceof String || typeof obj.value === 'number' || typeof obj.value === 'boolean') {
1941
return <span style={{background: '#00000010', padding: '3px'}}>{obj.value}</span>
@@ -23,34 +45,34 @@ function unsafe_format(obj) {
2345
} else if (typeof obj === 'string' || obj instanceof String) {
2446
return <i>{obj}</i>;
2547
} else if (typeof obj == 'object' && 'instance' in obj) {
26-
// @todo turn into actual instance in DB
2748
return <span style={{padding: '3px', borderBottom: 'dotted 3px gray'}}>{obj.instance}</span>
2849
} else if (typeof obj == 'object' && 'entity' in obj) {
29-
// @todo actual URL for schema
3050
var entity = obj.entity.split('(#')[0];
3151
return <a href={`https://ifc43-docs.standards.buildingsmart.org/IFC/RELEASE/IFC4x3/HTML/lexical/${entity}.htm`}>{entity}</a>
3252
} else if (typeof obj == 'object' && 'oneOf' in obj) {
33-
let ctx = obj.context ? `${obj.context.charAt(0).toUpperCase()}${obj.context.slice(1)} one of:` : `One of:`
34-
return <div>{ctx}<div></div><ul>{obj.oneOf.map(v =><li>{v}</li>)}</ul></div>
35-
} else if (typeof obj== 'object' && 'num_digits' in obj) {
36-
// custom formatting for calculated alignment consistency (e.g. ALS016, ALS017, ALS018)
37-
let ctx = obj.context ? `${obj.context.charAt(0).toUpperCase()}${obj.context.slice(1)} :` : `One of:`
53+
let ctx = obj.context ? `${obj.context.charAt(0).toUpperCase()}${obj.context.slice(1)} one of:` : `One of:`;
54+
return <div>{ctx}<div></div><ul>{obj.oneOf.map(v => <li>{v}</li>)}</ul></div>;
55+
} else if (typeof obj == 'object' && 'num_digits' in obj) {
56+
// Custom formatting for calculated alignment consistency
57+
let ctx = obj.context ? `${obj.context.charAt(0).toUpperCase()}${obj.context.slice(1)} :` : `One of:`;
3858
let value = obj.expected || obj.observed;
3959
let display_value = value.toExponential(obj.num_digits);
4060
if ('continuity_details' in obj) {
4161
let dts = obj.continuity_details;
42-
return <div>
43-
<div>{ctx} {display_value}</div>
44-
<div>at end of {dts.previous_segment}</div>
45-
<ul>Coords: ({dts.preceding_end_point[0]}, {dts.preceding_end_point[1]})</ul>
46-
<ul>Tangent Direction: {dts.preceding_end_direction}</ul>
47-
<br/>
48-
<div>and start of {dts.segment_to_analyze}</div>
49-
<ul>Coords: ({dts.current_start_point[0]}, {dts.current_start_point[1]})</ul>
50-
<ul>Tangent Direction: {dts.current_start_direction}</ul>
51-
</div>
62+
return (
63+
<div>
64+
<div>{ctx} {display_value}</div>
65+
<div>at end of {dts.previous_segment}</div>
66+
<ul>Coords: ({dts.preceding_end_point[0]}, {dts.preceding_end_point[1]})</ul>
67+
<ul>Tangent Direction: {dts.preceding_end_direction}</ul>
68+
<br />
69+
<div>and start of {dts.segment_to_analyze}</div>
70+
<ul>Coords: ({dts.current_start_point[0]}, {dts.current_start_point[1]})</ul>
71+
<ul>Tangent Direction: {dts.current_start_direction}</ul>
72+
</div>
73+
);
5274
} else {
53-
return <div>{ctx} {display_value}</div>
75+
return <div>{ctx} {display_value}</div>;
5476
}
5577
} else {
5678
return JSON.stringify(obj);

0 commit comments

Comments
 (0)