Procházet zdrojové kódy

chore: Turn up golang lint, and fix some minor error handling stuff

jamesread před 3 týdny
rodič
revize
a080f4ee2d

+ 9 - 0
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

+ 2 - 1
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)
 	}
 

+ 3 - 2
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."
 		})

+ 2 - 1
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{

+ 3 - 2
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
 	}