Skip to content

Commit

Permalink
refactor: Change all Needs Waitgroup errors into static errors.
Browse files Browse the repository at this point in the history
 #lint
  • Loading branch information
jaqx0r committed Jan 14, 2024
1 parent 490acbc commit 27f50b1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
9 changes: 7 additions & 2 deletions internal/exporter/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,18 @@ func DisableExport() Option {
}
}

var (
ErrNeedsStore = errors.New("exporter needs a Store")
ErrNeedsWaitgroup = errors.New("exporter needs a WaitGroup")
)

// New creates a new Exporter.
func New(ctx context.Context, wg *sync.WaitGroup, store *metrics.Store, options ...Option) (*Exporter, error) {
if store == nil {
return nil, errors.New("exporter needs a Store")
return nil, ErrNeedsStore
}
if wg == nil {
return nil, errors.New("exporter needs a WaitGroup")
return nil, ErrNeedsWaitgroup
}
e := &Exporter{
ctx: ctx,
Expand Down
4 changes: 3 additions & 1 deletion internal/mtail/exec_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func TestExecMtail(t *testing.T) {
t.Skip()
}

cs := []string{"-progs", "../../examples",
cs := []string{
"-progs",
"../../examples",
"-logs", "testdata/rsyncd.log",
"-one_shot",
"-one_shot_format=prometheus",
Expand Down
9 changes: 7 additions & 2 deletions internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,18 @@ type Runtime struct {
signalQuit chan struct{} // When closed stops the signal handler goroutine.
}

var (
ErrNeedsStore = errors.New("loader needs a store")
ErrNeedsWaitgroup = errors.New("loader needs a WaitGroup")
)

// New creates a new program loader that reads programs from programPath.
func New(lines <-chan *logline.LogLine, wg *sync.WaitGroup, programPath string, store *metrics.Store, options ...Option) (*Runtime, error) {
if store == nil {
return nil, errors.New("loader needs a store")
return nil, ErrNeedsStore
}
if wg == nil {
return nil, errors.New("loader needs a WaitGroup")
return nil, ErrNeedsWaitgroup
}
r := &Runtime{
ms: store,
Expand Down
3 changes: 2 additions & 1 deletion internal/tailer/logstream/logstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
ErrUnsupportedURLScheme = errors.New("unsupported URL scheme")
ErrUnsupportedFileType = errors.New("unsupported file type")
ErrEmptySocketAddress = errors.New("socket address cannot be empty, please provide a unix domain socket filename or host:port")
ErrNeedsWaitgroup = errors.New("logstream needs a waitgroup")
)

// New creates a LogStream from the file object located at the absolute path
Expand All @@ -55,7 +56,7 @@ var (
// files that can be seeked.
func New(ctx context.Context, wg *sync.WaitGroup, waker waker.Waker, pathname string, lines chan<- *logline.LogLine, oneShot bool) (LogStream, error) {
if wg == nil {
return nil, errors.New("logstream needs a WaitGroup")
return nil, ErrNeedsWaitgroup
}
u, err := url.Parse(pathname)
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions internal/tailer/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,18 @@ func (opt logstreamPollWaker) apply(t *Tailer) error {
return nil
}

var ErrNoLinesChannel = errors.New("Tailer needs a lines channel")
var (
ErrNoLinesChannel = errors.New("Tailer needs a lines channel")
ErrNeedsWaitgroup = errors.New("tailer needs a WaitGroup")
)

// New creates a new Tailer.
func New(ctx context.Context, wg *sync.WaitGroup, lines chan<- *logline.LogLine, options ...Option) (*Tailer, error) {
if lines == nil {
return nil, ErrNoLinesChannel
}
if wg == nil {
return nil, errors.New("tailer needs a WaitGroup")
return nil, ErrNeedsWaitgroup
}
t := &Tailer{
ctx: ctx,
Expand Down

0 comments on commit 27f50b1

Please sign in to comment.