Skip to content

Commit 9df5a47

Browse files
committed
[gopls-release-branch.0.3] internal/lsp/cache: handle invalid analysis Pos
The nilness analysis gives us diagnostics with invalid start Pos. We can just ignore those and log them. Add a missing error check while I'm in here. Change-Id: I4a205f253a9e47ec1513ff6299479f52e414a48c Reviewed-on: https://go-review.googlesource.com/c/tools/+/216724 Run-TryBot: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]> (cherry picked from commit e1fd582) Reviewed-on: https://go-review.googlesource.com/c/tools/+/216845
1 parent 234a0f4 commit 9df5a47

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

internal/lsp/cache/analysis.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"golang.org/x/tools/internal/lsp/telemetry"
2020
"golang.org/x/tools/internal/memoize"
2121
"golang.org/x/tools/internal/telemetry/log"
22+
"golang.org/x/tools/internal/telemetry/tag"
2223
errors "golang.org/x/xerrors"
2324
)
2425

@@ -319,13 +320,15 @@ func runAnalysis(ctx context.Context, fset *token.FileSet, analyzer *analysis.An
319320
return data
320321
}
321322
data.result, data.err = pass.Analyzer.Run(pass)
322-
if data.err == nil {
323-
if got, want := reflect.TypeOf(data.result), pass.Analyzer.ResultType; got != want {
324-
data.err = errors.Errorf(
325-
"internal error: on package %s, analyzer %s returned a result of type %v, but declared ResultType %v",
326-
pass.Pkg.Path(), pass.Analyzer, got, want)
327-
return data
328-
}
323+
if data.err != nil {
324+
return data
325+
}
326+
327+
if got, want := reflect.TypeOf(data.result), pass.Analyzer.ResultType; got != want {
328+
data.err = errors.Errorf(
329+
"internal error: on package %s, analyzer %s returned a result of type %v, but declared ResultType %v",
330+
pass.Pkg.Path(), pass.Analyzer, got, want)
331+
return data
329332
}
330333

331334
// disallow calls after Run
@@ -339,8 +342,8 @@ func runAnalysis(ctx context.Context, fset *token.FileSet, analyzer *analysis.An
339342
for _, diag := range diagnostics {
340343
srcErr, err := sourceError(ctx, fset, pkg, diag)
341344
if err != nil {
342-
data.err = err
343-
return data
345+
log.Error(ctx, "unable to compute analysis error position", err, tag.Of("category", diag.Category), telemetry.Package.Of(pkg.ID()))
346+
continue
344347
}
345348
data.diagnostics = append(data.diagnostics, srcErr)
346349
}

internal/span/token.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ func (r Range) IsPoint() bool {
6161
// It will fill in all the members of the Span, calculating the line and column
6262
// information.
6363
func (r Range) Span() (Span, error) {
64+
if !r.Start.IsValid() {
65+
return Span{}, fmt.Errorf("start pos is not valid")
66+
}
6467
f := r.FileSet.File(r.Start)
6568
if f == nil {
6669
return Span{}, fmt.Errorf("file not found in FileSet")

0 commit comments

Comments
 (0)