mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:10 -07:00
44a64ad78b
Instead of checking the context, check the error. This may expose some errors that are not wrapped correctly. Replaced all uses of errors with golang.org/x/xerrors. Change-Id: Ia40160f8ea352e02618765f2a9415a4ece0dcd94 Reviewed-on: https://go-review.googlesource.com/c/tools/+/227036 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
36 lines
695 B
Go
36 lines
695 B
Go
package protocol
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"golang.org/x/tools/internal/telemetry/event"
|
|
"golang.org/x/tools/internal/xcontext"
|
|
)
|
|
|
|
type contextKey int
|
|
|
|
const (
|
|
clientKey = contextKey(iota)
|
|
)
|
|
|
|
func WithClient(ctx context.Context, client Client) context.Context {
|
|
return context.WithValue(ctx, clientKey, client)
|
|
}
|
|
|
|
func LogEvent(ctx context.Context, ev event.Event, tags event.TagMap) context.Context {
|
|
if !ev.IsLog() {
|
|
return ctx
|
|
}
|
|
client, ok := ctx.Value(clientKey).(Client)
|
|
if !ok {
|
|
return ctx
|
|
}
|
|
msg := &LogMessageParams{Type: Info, Message: fmt.Sprint(ev)}
|
|
if event.Err.Get(tags) != nil {
|
|
msg.Type = Error
|
|
}
|
|
go client.LogMessage(xcontext.Detach(ctx), msg)
|
|
return ctx
|
|
}
|