Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use slog.Error
  • Loading branch information
mtojek committed Jun 19, 2023
commit e47ecfd3ebacf13b483c01529f72d7c18145265c
2 changes: 1 addition & 1 deletion coderd/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (h *HTTPAuthorizer) Authorize(r *http.Request, action rbac.Action, object r
internalError := new(rbac.UnauthorizedError)
logger := h.Logger
if xerrors.As(err, internalError) {
logger = h.Logger.With(slog.F("internal", internalError.Internal()))
logger = h.Logger.With(slog.F("internal_error", internalError.Internal()))
}
// Log information for debugging. This will be very helpful
// in the early days
Expand Down
2 changes: 1 addition & 1 deletion coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func logNotAuthorizedError(ctx context.Context, logger slog.Logger, err error) e
return &contextError
}
logger.Debug(ctx, "unauthorized",
slog.F("internal", internalError.Internal()),
slog.F("internal_error", internalError.Internal()),
slog.F("input", internalError.Input()),
slog.Error(err),
)
Expand Down
2 changes: 1 addition & 1 deletion coderd/httpmw/clitelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func ReportCLITelemetry(log slog.Logger, rep telemetry.Reporter) func(http.Handl
log.Error(
r.Context(),
"base64 decode",
slog.F("error", err),
slog.Error(err),
)
return
}
Expand Down
4 changes: 2 additions & 2 deletions enterprise/derpmesh/derpmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func (m *Mesh) SetAddresses(addresses []string, connect bool) {
for _, address := range addresses {
addressURL, err := url.Parse(address)
if err != nil {
m.logger.Error(m.ctx, "invalid address", slog.F("address", err), slog.Error(err))
m.logger.Error(m.ctx, "invalid address", slog.F("address", address), slog.Error(err))
continue
}
derpURL, err := addressURL.Parse("/derp")
if err != nil {
m.logger.Error(m.ctx, "parse derp", slog.F("address", err), slog.Error(err))
m.logger.Error(m.ctx, "parse derp", slog.F("address", addressURL.String()), slog.Error(err))
continue
}
address = derpURL.String()
Expand Down
10 changes: 10 additions & 0 deletions scripts/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,13 @@ func slogMessageLength(m dsl.Matcher) {
!m["message"].Text.Matches(`^"command exit"$`)).
Report(`Message $message is too short, it must be at least 16 characters long.`)
}

// slogErr ensures that errors are logged with "slog.Error" instead of "slog.F"
func slogError(m dsl.Matcher) {
m.Import("cdr.dev/slog")
m.Match(
`slog.F($name, $value)`,
).
Where(m["name"].Const && m["value"].Type.Is("error") && !m["name"].Text.Matches(`^"internal_error"$`)).
Report(`Error should be logged using "slog.Error" instead.`)
}
2 changes: 1 addition & 1 deletion tailnet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func NewConn(options *Options) (conn *Conn, err error) {
}
}()
wireguardEngine.SetStatusCallback(func(s *wgengine.Status, err error) {
server.logger.Debug(context.Background(), "wireguard status", slog.F("status", s), slog.F("err", err))
server.logger.Debug(context.Background(), "wireguard status", slog.F("status", s), slog.Error(err))
if err != nil {
return
}
Expand Down