Skip to content

Commit

Permalink
Don't allocate new error inside TaskLoop
Browse files Browse the repository at this point in the history
Libraries use errors.Is to catch this error. Allocating a new one inside
internal breaks that
  • Loading branch information
Sean-Der committed Jul 25, 2024
1 parent f15ba98 commit b7206e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

package ice

import "errors"
import (
"errors"

"github.com/pion/ice/v3/internal/taskloop"
)

var (
// ErrUnknownType indicates an error with Unknown info.
Expand Down Expand Up @@ -36,7 +40,7 @@ var (
ErrProtoType = errors.New("invalid transport protocol type")

// ErrClosed indicates the agent is closed
ErrClosed = errors.New("the agent is closed")
ErrClosed = taskloop.ErrClosed

// ErrNoCandidatePairs indicates agent does not have a valid candidate pair
ErrNoCandidatePairs = errors.New("no candidate pairs available")
Expand Down
8 changes: 4 additions & 4 deletions internal/taskloop/taskloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
atomicx "github.com/pion/ice/v3/internal/atomic"
)

// errClosed indicates that the loop has been stopped
var errClosed = errors.New("the agent is closed")
// ErrClosed indicates that the loop has been stopped
var ErrClosed = errors.New("the agent is closed")

type task struct {
fn func(context.Context)
Expand Down Expand Up @@ -68,7 +68,7 @@ func (l *Loop) Close() error {
return err
}

l.err.Store(errClosed)
l.err.Store(ErrClosed)

Check warning on line 71 in internal/taskloop/taskloop.go

View check run for this annotation

Codecov / codecov/patch

internal/taskloop/taskloop.go#L71

Added line #L71 was not covered by tests

close(l.done)
<-l.taskLoopDone
Expand Down Expand Up @@ -104,7 +104,7 @@ func (l *Loop) Done() <-chan struct{} {
func (l *Loop) Err() error {
select {
case <-l.done:
return errClosed
return ErrClosed

Check warning on line 107 in internal/taskloop/taskloop.go

View check run for this annotation

Codecov / codecov/patch

internal/taskloop/taskloop.go#L107

Added line #L107 was not covered by tests
default:
return nil
}
Expand Down

0 comments on commit b7206e2

Please sign in to comment.