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

This commit is contained in:
jamesread 2026-07-28 22:11:37 +01:00
parent d7758a91c4
commit a080f4ee2d
5 changed files with 19 additions and 6 deletions

View File

@ -7,12 +7,19 @@ run:
linters: linters:
default: none default: none
enable: enable:
- bidichk
- bodyclose
- durationcheck
- errcheck - errcheck
- errorlint
- gocritic - gocritic
- gocyclo - gocyclo
- gosec - gosec
- govet
- ineffassign - ineffassign
- misspell - misspell
- nilerr
- noctx
- staticcheck - staticcheck
- unconvert - unconvert
- unused - unused
@ -22,6 +29,8 @@ linters:
gosec: gosec:
# Full gosec rule set (G101–G6xx), including Slowloris checks G112/G114. # Full gosec rule set (G101–G6xx), including Slowloris checks G112/G114.
enable-all-rules: true enable-all-rules: true
govet:
enable-all: true
exclusions: exclusions:
paths: paths:
- gen - gen

View File

@ -311,7 +311,8 @@ func (api *oliveTinAPI) StartActionAndWait(ctx ctx.Context, req *connect.Request
user := auth.UserFromApiCall(ctx, req, api.cfg) user := auth.UserFromApiCall(ctx, req, api.cfg)
args := startActionArgumentsFromProto(req.Msg.Arguments) args := startActionArgumentsFromProto(req.Msg.Arguments)
justification := resolveStartJustification(binding.Action, binding, req.Msg.Justification, args) 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) return nil, connectInvalidJustification(err)
} }

View File

@ -22,6 +22,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"sync" "sync"
"errors"
"time" "time"
) )
@ -1186,7 +1187,7 @@ func stepExec(req *ExecutionRequest) bool {
appendErrorToStderr(req, runerr) appendErrorToStderr(req, runerr)
appendErrorToStderr(req, waiterr) appendErrorToStderr(req, waiterr)
if ctx.Err() == context.DeadlineExceeded { if errors.Is(ctx.Err(), context.DeadlineExceeded) {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"actionTitle": req.logEntry.ActionTitle, "actionTitle": req.logEntry.ActionTitle,
}).Warnf("Action timed out") }).Warnf("Action timed out")
@ -1263,7 +1264,7 @@ func stepExecAfter(req *ExecutionRequest) bool {
appendErrorToStderr(req, runerr) appendErrorToStderr(req, runerr)
appendErrorToStderr(req, waiterr) appendErrorToStderr(req, waiterr)
if ctx.Err() == context.DeadlineExceeded { if errors.Is(ctx.Err(), context.DeadlineExceeded) {
req.mutateLogEntry(func(entry *InternalLogEntry) { req.mutateLogEntry(func(entry *InternalLogEntry) {
entry.Output += "Your shellAfterCompleted command timed out." entry.Output += "Your shellAfterCompleted command timed out."
}) })

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"sync" "sync"
"time" "time"
"errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -55,7 +56,7 @@ func (tc *timeoutContext) setProcess(process *os.Process) {
tc.processMu.Unlock() tc.processMu.Unlock()
// If deadline already expired before process was set, kill now // 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} logEntry := &InternalLogEntry{Process: process}
if err := tc.executor.Kill(logEntry); err != nil { if err := tc.executor.Kill(logEntry); err != nil {
log.WithFields(log.Fields{ log.WithFields(log.Fields{

View File

@ -10,6 +10,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
"errors"
log "github.com/sirupsen/logrus" 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) { func finishTestCommand(cmd *exec.Cmd, state *testRunState) (int, runSummary, []testFailure, error) {
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
if exitErr, ok := err.(*exec.ExitError); ok { if errExit, ok := errors.AsType[*exec.ExitError](err); ok {
state.finalizeFailureOutputs() 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 return 1, state.summary, state.failures, err
} }