diff --git a/service/.golangci.yml b/service/.golangci.yml index 6719989c..d5448ff3 100644 --- a/service/.golangci.yml +++ b/service/.golangci.yml @@ -7,12 +7,19 @@ run: linters: default: none enable: + - bidichk + - bodyclose + - durationcheck - errcheck + - errorlint - gocritic - gocyclo - gosec + - govet - ineffassign - misspell + - nilerr + - noctx - staticcheck - unconvert - unused @@ -22,6 +29,8 @@ linters: gosec: # Full gosec rule set (G101–G6xx), including Slowloris checks G112/G114. enable-all-rules: true + govet: + enable-all: true exclusions: paths: - gen diff --git a/service/internal/api/api.go b/service/internal/api/api.go index 477a2fee..fa3a8bb3 100644 --- a/service/internal/api/api.go +++ b/service/internal/api/api.go @@ -311,7 +311,8 @@ func (api *oliveTinAPI) StartActionAndWait(ctx ctx.Context, req *connect.Request user := auth.UserFromApiCall(ctx, req, api.cfg) args := startActionArgumentsFromProto(req.Msg.Arguments) justification := resolveStartJustification(binding.Action, binding, req.Msg.Justification, args) - if err := validateJustificationRequired(binding.Action, justification, user); err != nil { + + if err = validateJustificationRequired(binding.Action, justification, user); err != nil { return nil, connectInvalidJustification(err) } diff --git a/service/internal/executor/executor.go b/service/internal/executor/executor.go index e95bca33..434c2e05 100644 --- a/service/internal/executor/executor.go +++ b/service/internal/executor/executor.go @@ -22,6 +22,7 @@ import ( "regexp" "strings" "sync" + "errors" "time" ) @@ -1186,7 +1187,7 @@ func stepExec(req *ExecutionRequest) bool { appendErrorToStderr(req, runerr) appendErrorToStderr(req, waiterr) - if ctx.Err() == context.DeadlineExceeded { + if errors.Is(ctx.Err(), context.DeadlineExceeded) { log.WithFields(log.Fields{ "actionTitle": req.logEntry.ActionTitle, }).Warnf("Action timed out") @@ -1263,7 +1264,7 @@ func stepExecAfter(req *ExecutionRequest) bool { appendErrorToStderr(req, runerr) appendErrorToStderr(req, waiterr) - if ctx.Err() == context.DeadlineExceeded { + if errors.Is(ctx.Err(), context.DeadlineExceeded) { req.mutateLogEntry(func(entry *InternalLogEntry) { entry.Output += "Your shellAfterCompleted command timed out." }) diff --git a/service/internal/executor/timeout_context.go b/service/internal/executor/timeout_context.go index 2375edf2..90643099 100644 --- a/service/internal/executor/timeout_context.go +++ b/service/internal/executor/timeout_context.go @@ -5,6 +5,7 @@ import ( "os" "sync" "time" + "errors" log "github.com/sirupsen/logrus" ) @@ -55,7 +56,7 @@ func (tc *timeoutContext) setProcess(process *os.Process) { tc.processMu.Unlock() // If deadline already expired before process was set, kill now - if tc.Err() == context.DeadlineExceeded && process != nil { + if errors.Is(tc.Err(), context.DeadlineExceeded) && process != nil { logEntry := &InternalLogEntry{Process: process} if err := tc.executor.Kill(logEntry); err != nil { log.WithFields(log.Fields{ diff --git a/service/scripts/find-flakey-tests-inf/main.go b/service/scripts/find-flakey-tests-inf/main.go index a890bd91..aa662447 100644 --- a/service/scripts/find-flakey-tests-inf/main.go +++ b/service/scripts/find-flakey-tests-inf/main.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strings" "time" + "errors" log "github.com/sirupsen/logrus" ) @@ -312,9 +313,9 @@ func scanTestEvents(stdout io.Reader, state *testRunState) error { func finishTestCommand(cmd *exec.Cmd, state *testRunState) (int, runSummary, []testFailure, error) { if err := cmd.Wait(); err != nil { - if exitErr, ok := err.(*exec.ExitError); ok { + if errExit, ok := errors.AsType[*exec.ExitError](err); ok { state.finalizeFailureOutputs() - return exitErr.ExitCode(), state.summary, state.failures, nil + return errExit.ExitCode(), state.summary, state.failures, nil } return 1, state.summary, state.failures, err }