Skip to content

Commit f3a5411

Browse files
committed
internal/lsp: fix panic when trying to log an event
Formatting keys in labels can panic when a label is constructed with a nil error. Avoid that by not passing the defective label to event.Log. Change-Id: I3099a7ac48c5830af1072141f2b619d0e0fbcf5a Reviewed-on: https://go-review.googlesource.com/c/tools/+/229985 Run-TryBot: Peter Weinberger <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Cottrell <[email protected]>
1 parent 8463f39 commit f3a5411

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/lsp/cache/view.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,11 @@ func (v *view) refreshProcessEnv() {
345345
// We don't have a context handy to use for logging, so use the stdlib for now.
346346
event.Log(v.baseCtx, "background imports cache refresh starting")
347347
err := imports.PrimeCache(context.Background(), env)
348-
event.Log(v.baseCtx, fmt.Sprintf("background refresh finished after %v", time.Since(start)), keys.Err.Of(err))
349-
348+
if err == nil {
349+
event.Log(v.baseCtx, fmt.Sprintf("background refresh finished after %v", time.Since(start)))
350+
} else {
351+
event.Log(v.baseCtx, fmt.Sprintf("background refresh finished after %v", time.Since(start)), keys.Err.Of(err))
352+
}
350353
v.importsMu.Lock()
351354
v.cacheRefreshDuration = time.Since(start)
352355
v.cacheRefreshTimer = nil

0 commit comments

Comments
 (0)