From 547333d2a59bec7120eeffb5069c8bb2bd74eca3 Mon Sep 17 00:00:00 2001 From: Jumping Cat Date: Wed, 18 Sep 2024 09:32:58 +0200 Subject: [PATCH] refactor: clean up code for errors from golangci-lint (#18) --- bcd.go | 14 ++++++-------- main.go | 8 ++++---- main_test.go | 8 ++++---- threads.go | 4 ++-- tracer_darwin_stub.go | 20 ++++++++++++++------ 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/bcd.go b/bcd.go index 1c75bee..52d3bad 100644 --- a/bcd.go +++ b/bcd.go @@ -271,7 +271,7 @@ func (s *signalError) Error() string { // be resent to the default Go handler for that signal. func Register(t TracerSig) { ss := t.Sigset() - if ss == nil || len(ss) == 0 { + if ss == nil { t.Logf(LogError, "Failed to register signal handler: empty "+ "sigset\n") return @@ -297,7 +297,7 @@ func Register(t TracerSig) { for s := range c { t.Logf(LogDebug, "Received %v; executing tracer\n", s) - Trace(t, &signalError{s}, nil) + _ = Trace(t, &signalError{s}, nil) if !rs { continue @@ -314,13 +314,11 @@ func Register(t TracerSig) { return } - p.Signal(s) + _ = p.Signal(s) } t.Logf(LogDebug, "Signal channel closed; exiting goroutine\n") }(t) - - return } // Stops the specified TracerSig from handling any signals it was previously @@ -522,7 +520,7 @@ func Trace(t Tracer, e error, traceOptions *TraceOptions) (err error) { return } - if t.PutOnTrace() == false { + if !t.PutOnTrace() { t.Logf(LogDebug, "Trace request complete\n") return @@ -557,7 +555,7 @@ func Trace(t Tracer, e error, traceOptions *TraceOptions) (err error) { defer traceOptions.SpawnedGs.Done() } - putFn() + _ = putFn() }() } @@ -598,7 +596,7 @@ func Recover(t Tracer, repanic bool, options *TraceOptions) { err = &panicError{r} } - Trace(t, err, options) + _ = Trace(t, err, options) if repanic { panic(r) diff --git a/main.go b/main.go index 475c7fe..a75b929 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( cryptorand "crypto/rand" "encoding/json" "fmt" - "io/ioutil" + "io" mathrand "math/rand" "net/http" "net/url" @@ -218,7 +218,7 @@ func sendWorkerMain() { case *reportPayload: processAndSend(value) default: - panic(fmt.Sprintf("invalid queue item")) + panic("invalid queue item") } case <-block_chan: done_chan <- struct{}{} @@ -282,8 +282,8 @@ func processAndSend(payload *reportPayload) { return } defer resp.Body.Close() - _, err = ioutil.ReadAll(resp.Body) - if err != nil { + + if _, err = io.ReadAll(resp.Body); err != nil { if Options.DebugBacktrace { panic(err) } diff --git a/main_test.go b/main_test.go index 80e3b91..35f0af9 100644 --- a/main_test.go +++ b/main_test.go @@ -4,7 +4,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net" "net/http" "os" @@ -50,7 +50,7 @@ func TestPanic(t *testing.T) { for i := 0; i < 5; i++ { func() { defer func() { - recover() + _ = recover() count++ }() func() { @@ -74,7 +74,7 @@ func (h myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { defer h.listener.Close() var err error - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { panic(err) } @@ -96,7 +96,7 @@ func (h myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func doSomething(ch chan int) { - _ = <-ch + <-ch } func causeErrorReport() { diff --git a/threads.go b/threads.go index ff1629a..e3b7ff4 100644 --- a/threads.go +++ b/threads.go @@ -2,7 +2,7 @@ package bt import ( "bytes" - "io/ioutil" + "os" "regexp" "strconv" ) @@ -81,7 +81,7 @@ func collectSource(sourcePath string, sourcePathToID map[string]string, sourceCo sourceCodeObject := map[string]interface{}{} - bytes, err := ioutil.ReadFile(sourcePath) + bytes, err := os.ReadFile(sourcePath) if err == nil { sourceCodeObject["text"] = string(bytes) sourceCodeObject["startLine"] = 1 diff --git a/tracer_darwin_stub.go b/tracer_darwin_stub.go index 279ff72..cb2e554 100644 --- a/tracer_darwin_stub.go +++ b/tracer_darwin_stub.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package bt @@ -13,11 +14,13 @@ import ( "sync" ) +//nolint:all type pipes struct { stdin io.Reader stderr io.Writer } +//nolint:all type uploader struct { endpoint string options PutOptions @@ -28,31 +31,31 @@ type BTTracer struct { cmd string // Output directory for generated snapshots. - outputDir string + outputDir string //nolint:all // Generic options to pass to the tracer. options []string // Prefix for key-value options. - kvp string + kvp string //nolint:all // Delimeter between key and value for key-value options. - kvd string + kvd string //nolint:all // Channel which receives signal notifications. sigs chan os.Signal // The set of signals the tracer will monitor. - ss []os.Signal + ss []os.Signal //nolint:all // The pipes to use for tracer I/O. - p pipes + p pipes //nolint:all // Protects tracer state modification. m sync.RWMutex // Logs tracer execution status messages. - logger Log + logger Log //nolint:all // Default trace options to use if none are specified to bt.Trace(). defaultTraceOptions TraceOptions @@ -61,14 +64,17 @@ type BTTracer struct { put uploader } +//nolint:all type defaultLogger struct { logger *log.Logger level LogPriority } +//nolint:all func (d *defaultLogger) Logf(level LogPriority, format string, v ...interface{}) { } +//nolint:all func (d *defaultLogger) SetLogLevel(level LogPriority) { } @@ -117,10 +123,12 @@ func (t *BTTracer) PutDir(path string) error { return nil } +//nolint:all func putDirWalk(t *BTTracer) filepath.WalkFunc { return nil } +//nolint:all func (t *BTTracer) putSnapshotFile(path string) error { return nil }