Skip to content

Commit

Permalink
refactor: clean up code for errors from golangci-lint (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKepczynskiSauce authored Sep 18, 2024
1 parent 7b1b34a commit 547333d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
14 changes: 6 additions & 8 deletions bcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -557,7 +555,7 @@ func Trace(t Tracer, e error, traceOptions *TraceOptions) (err error) {
defer traceOptions.SpawnedGs.Done()
}

putFn()
_ = putFn()
}()
}

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
cryptorand "crypto/rand"
"encoding/json"
"fmt"
"io/ioutil"
"io"
mathrand "math/rand"
"net/http"
"net/url"
Expand Down Expand Up @@ -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{}{}
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestPanic(t *testing.T) {
for i := 0; i < 5; i++ {
func() {
defer func() {
recover()
_ = recover()
count++
}()
func() {
Expand All @@ -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)
}
Expand All @@ -96,7 +96,7 @@ func (h myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

func doSomething(ch chan int) {
_ = <-ch
<-ch
}

func causeErrorReport() {
Expand Down
4 changes: 2 additions & 2 deletions threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bt

import (
"bytes"
"io/ioutil"
"os"
"regexp"
"strconv"
)
Expand Down Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions tracer_darwin_stub.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build darwin
// +build darwin

package bt
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 547333d

Please sign in to comment.