Skip to content

Commit 239570a

Browse files
authored
fix(4677): lsp helper methods need to be error handled. (#4786)
1 parent 3b24d1d commit 239570a

File tree

6 files changed

+50
-25
lines changed

6 files changed

+50
-25
lines changed

src/flows/pipes/Notification/view.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
} from 'src/flows/pipes/Notification/endpoints'
4343
import {SidebarContext} from 'src/flows/context/sidebar'
4444
import ExportTask from 'src/flows/pipes/Notification/ExportTask'
45+
import ErrorBoundary from 'src/shared/components/ErrorBoundary'
4546
const NotificationMonacoEditor = lazy(() =>
4647
import('src/flows/pipes/Notification/NotificationMonacoEditor')
4748
)
@@ -481,7 +482,9 @@ const Notification: FC<PipeProp> = ({Context}) => {
481482
</FlexBox>
482483
<Panel.Footer justifyContent={JustifyContent.FlexEnd}>
483484
<FlexBox margin={ComponentSize.Medium}>
484-
<ExportTask />
485+
<ErrorBoundary>
486+
<ExportTask />
487+
</ErrorBoundary>
485488
</FlexBox>
486489
</Panel.Footer>
487490
</div>

src/languageSupport/languages/flux/lsp/prelude.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class Prelude {
4040
)
4141
)
4242
}
43-
} catch (_) {}
43+
} catch (e) {
44+
console.error(e)
45+
}
4446
}
4547

4648
subscribeToModel(editor: EditorType) {

src/languageSupport/languages/flux/lsp/worker/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ export const respond = (msg, cb) => {
22
try {
33
const d = JSON.parse(msg)
44
cb(d)
5-
} catch (_) {}
5+
} catch (e) {
6+
console.warn(e)
7+
}
68
}

src/timeMachine/actions/queries.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,20 @@ export const getOrgIDFromBuckets = (
8181
text: string,
8282
allBuckets: Bucket[]
8383
): string | null => {
84-
const ast = parse(text)
85-
const bucketsInQuery: string[] = findNodes(ast, isFromBucket).map(node =>
86-
get(node, 'arguments.0.properties.0.value.value', '')
87-
)
84+
try {
85+
const ast = parse(text)
86+
const bucketsInQuery: string[] = findNodes(ast, isFromBucket).map(node =>
87+
get(node, 'arguments.0.properties.0.value.value', '')
88+
)
8889

89-
// if there are buckets from multiple orgs in a query, query will error, and user will receive error from query
90-
const bucketMatch = allBuckets.find(a => bucketsInQuery.includes(a.name))
90+
// if there are buckets from multiple orgs in a query, query will error, and user will receive error from query
91+
const bucketMatch = allBuckets.find(a => bucketsInQuery.includes(a.name))
9192

92-
return get(bucketMatch, 'orgID', null)
93+
return get(bucketMatch, 'orgID', null)
94+
} catch (e) {
95+
console.error(e)
96+
return null
97+
}
9398
}
9499

95100
// We only need a minimum of one bucket, function, and tag,

src/variables/utils/astim.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@ const parseAllVariables = (ast: File): MemberExpression[] => {
1919
}
2020

2121
export const parseASTIM = (query: string): ASTIM => {
22-
const ast: File = parse(query)
23-
// Using `any` to circumvent ts error
24-
const variables: any = ast ? parseAllVariables(ast) : []
22+
let ast: File = null
23+
try {
24+
ast = parse(query)
25+
} catch (e) {
26+
console.error(e)
27+
}
28+
const variables: MemberExpression[] = ast ? parseAllVariables(ast) : []
2529
const variableNames = new Set()
26-
variables.forEach(variable => variableNames.add(variable.property.name))
30+
variables.forEach(variable => {
31+
if (variable.property.type === 'Identifier') {
32+
variableNames.add(variable.property.name)
33+
} else if (variable.property.type === 'StringLiteral') {
34+
variableNames.add(variable.property.value)
35+
}
36+
})
2737

2838
const hasVariable = (v: string): boolean => {
2939
return variableNames.has(v)

src/writeData/components/ClientCodeQueryHelper.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,21 @@ const ClientCodeQueryHelper: FC<Props> = ({clientQuery, contentID}) => {
5050
changeQuery(def.query)
5151
return
5252
}
53-
54-
const ast = parse(clientQuery)
55-
const queryBucket = getBucketsFromAST(ast)[0]
56-
if (queryBucket) {
57-
changeBucket({name: queryBucket} as Bucket)
58-
}
59-
updateBucketInAST(ast, '<%= bucket %>')
60-
let query = format_from_js_file(ast)
61-
if (def.querySanitize) {
62-
query = def.querySanitize(query)
53+
try {
54+
const ast = parse(clientQuery)
55+
const queryBucket = getBucketsFromAST(ast)[0]
56+
if (queryBucket) {
57+
changeBucket({name: queryBucket} as Bucket)
58+
}
59+
updateBucketInAST(ast, '<%= bucket %>')
60+
let query = format_from_js_file(ast)
61+
if (def.querySanitize) {
62+
query = def.querySanitize(query)
63+
}
64+
changeQuery(query)
65+
} catch (e) {
66+
console.error(e)
6367
}
64-
changeQuery(query)
6568
}, [clientQuery, def.query, changeBucket, changeQuery])
6669

6770
return null

0 commit comments

Comments
 (0)