Skip to content

Commit 95f764f

Browse files
committed
fixed production runtime crashes
1 parent 0aebea5 commit 95f764f

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

analysis/hover.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func hoverOnSendStatement(sendStatement parser.SendStatement, position parser.Po
113113
}
114114

115115
func hoverOnLiteral(lit parser.Literal, position parser.Position) Hover {
116+
if lit == nil {
117+
return nil
118+
}
119+
116120
if !lit.GetRange().Contains(position) {
117121
return nil
118122
}
@@ -140,6 +144,10 @@ func hoverOnLiteral(lit parser.Literal, position parser.Position) Hover {
140144
}
141145

142146
func hoverOnSource(source parser.Source, position parser.Position) Hover {
147+
if source == nil {
148+
return nil
149+
}
150+
143151
if !source.GetRange().Contains(position) {
144152
return nil
145153
}
@@ -174,7 +182,7 @@ func hoverOnSource(source parser.Source, position parser.Position) Hover {
174182
case *parser.SourceInorder:
175183
for _, source := range source.Sources {
176184
// TODO binary search
177-
if !source.GetRange().Contains(position) {
185+
if source == nil || !source.GetRange().Contains(position) {
178186
continue
179187
}
180188

analysis/hover_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,50 @@ func TestHoverOnFnOriginDocs(t *testing.T) {
314314
}
315315

316316
}
317+
318+
func TestHoverFaultTolerance(t *testing.T) {
319+
t.Run("missing lit", func(t *testing.T) {
320+
input := `
321+
send [COIN 10] (
322+
source = max <invalidtk> from @a
323+
destination = @a
324+
)
325+
`
326+
327+
rng := RangeOfIndexed(input, "<invalidtk>", 0)
328+
program := parser.Parse(input).Value
329+
hover := analysis.HoverOn(program, rng.Start)
330+
assert.Nil(t, hover)
331+
})
332+
333+
t.Run("missing source", func(t *testing.T) {
334+
input := `
335+
send [COIN 10] (
336+
source = <invalidtk>
337+
destination = @a
338+
)
339+
`
340+
341+
rng := RangeOfIndexed(input, "<invalidtk>", 0)
342+
program := parser.Parse(input).Value
343+
hover := analysis.HoverOn(program, rng.Start)
344+
assert.Nil(t, hover)
345+
})
346+
347+
t.Run("missing source in inorder", func(t *testing.T) {
348+
input := `
349+
send [COIN 10] (
350+
source = {
351+
@a
352+
<invalidtk>
353+
}
354+
destination = @a
355+
)
356+
`
357+
358+
rng := RangeOfIndexed(input, "<invalidtk>", 0)
359+
program := parser.Parse(input).Value
360+
hover := analysis.HoverOn(program, rng.Start)
361+
assert.Nil(t, hover)
362+
})
363+
}

0 commit comments

Comments
 (0)