Skip to content

Commit

Permalink
chore: consolidate the import declarations of the internal error pack…
Browse files Browse the repository at this point in the history
…age (#501)
  • Loading branch information
panjf2000 authored Sep 10, 2023
1 parent f7830a4 commit 7699eae
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

gerr "github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
"github.com/panjf2000/gnet/v2/pkg/logging"
bbPool "github.com/panjf2000/gnet/v2/pkg/pool/bytebuffer"
goPool "github.com/panjf2000/gnet/v2/pkg/pool/goroutine"
Expand All @@ -30,8 +30,8 @@ type clientEvents struct {

func (ev *clientEvents) OnBoot(e Engine) Action {
fd, err := e.Dup()
require.ErrorIsf(ev.tester, err, gerr.ErrEmptyEngine, "expected error: %v, but got: %v",
gerr.ErrUnsupportedOp, err)
require.ErrorIsf(ev.tester, err, errorx.ErrEmptyEngine, "expected error: %v, but got: %v",
errorx.ErrUnsupportedOp, err)
assert.EqualValuesf(ev.tester, fd, -1, "expected -1, but got: %d", fd)
return None
}
Expand Down Expand Up @@ -80,8 +80,8 @@ func (ev *clientEvents) OnTick() (delay time.Duration, action Action) {

func (ev *clientEvents) OnShutdown(e Engine) {
fd, err := e.Dup()
require.ErrorIsf(ev.tester, err, gerr.ErrEmptyEngine, "expected error: %v, but got: %v",
gerr.ErrUnsupportedOp, err)
require.ErrorIsf(ev.tester, err, errorx.ErrEmptyEngine, "expected error: %v, but got: %v",
errorx.ErrUnsupportedOp, err)
assert.EqualValuesf(ev.tester, fd, -1, "expected -1, but got: %d", fd)
}

Expand Down
6 changes: 3 additions & 3 deletions client_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/panjf2000/gnet/v2/internal/netpoll"
"github.com/panjf2000/gnet/v2/internal/socket"
"github.com/panjf2000/gnet/v2/pkg/buffer/ring"
gerrors "github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
"github.com/panjf2000/gnet/v2/pkg/logging"
)

Expand Down Expand Up @@ -126,7 +126,7 @@ func (cli *Client) Start() error {

// Stop stops the client event-loop.
func (cli *Client) Stop() (err error) {
logging.Error(cli.el.poller.UrgentTrigger(func(_ interface{}) error { return gerrors.ErrEngineShutdown }, nil))
logging.Error(cli.el.poller.UrgentTrigger(func(_ interface{}) error { return errorx.ErrEngineShutdown }, nil))
// Stop the ticker.
if cli.opts.Ticker {
cli.el.engine.ticker.cancel()
Expand Down Expand Up @@ -215,7 +215,7 @@ func (cli *Client) Enroll(c net.Conn) (Conn, error) {
}
gc = newUDPConn(dupFD, cli.el, c.LocalAddr(), sockAddr, true)
default:
return nil, gerrors.ErrUnsupportedProtocol
return nil, errorx.ErrUnsupportedProtocol

Check warning on line 218 in client_unix.go

View check run for this annotation

Codecov / codecov/patch

client_unix.go#L218

Added line #L218 was not covered by tests
}
err = cli.el.poller.UrgentTrigger(cli.el.register, gc)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions connection_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/panjf2000/gnet/v2/internal/netpoll"
"github.com/panjf2000/gnet/v2/internal/socket"
"github.com/panjf2000/gnet/v2/pkg/buffer/elastic"
gerrors "github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
"github.com/panjf2000/gnet/v2/pkg/logging"
bsPool "github.com/panjf2000/gnet/v2/pkg/pool/byteslice"
)
Expand Down Expand Up @@ -355,7 +355,7 @@ func (c *conn) Write(p []byte) (int, error) {

func (c *conn) Writev(bs [][]byte) (int, error) {
if c.isDatagram {
return 0, gerrors.ErrUnsupportedOp
return 0, errorx.ErrUnsupportedOp

Check warning on line 358 in connection_unix.go

View check run for this annotation

Codecov / codecov/patch

connection_unix.go#L358

Added line #L358 was not covered by tests
}
return c.writev(bs)
}
Expand Down Expand Up @@ -437,7 +437,7 @@ func (c *conn) AsyncWrite(buf []byte, callback AsyncCallback) error {

func (c *conn) AsyncWritev(bs [][]byte, callback AsyncCallback) error {
if c.isDatagram {
return gerrors.ErrUnsupportedOp
return errorx.ErrUnsupportedOp

Check warning on line 440 in connection_unix.go

View check run for this annotation

Codecov / codecov/patch

connection_unix.go#L440

Added line #L440 was not covered by tests
}
return c.loop.poller.Trigger(c.asyncWritev, &asyncWritevHook{callback, bs})
}
Expand Down Expand Up @@ -470,13 +470,13 @@ func (c *conn) Close() error {
}

func (*conn) SetDeadline(_ time.Time) error {
return gerrors.ErrUnsupportedOp
return errorx.ErrUnsupportedOp

Check warning on line 473 in connection_unix.go

View check run for this annotation

Codecov / codecov/patch

connection_unix.go#L473

Added line #L473 was not covered by tests
}

func (*conn) SetReadDeadline(_ time.Time) error {
return gerrors.ErrUnsupportedOp
return errorx.ErrUnsupportedOp

Check warning on line 477 in connection_unix.go

View check run for this annotation

Codecov / codecov/patch

connection_unix.go#L477

Added line #L477 was not covered by tests
}

func (*conn) SetWriteDeadline(_ time.Time) error {
return gerrors.ErrUnsupportedOp
return errorx.ErrUnsupportedOp

Check warning on line 481 in connection_unix.go

View check run for this annotation

Codecov / codecov/patch

connection_unix.go#L481

Added line #L481 was not covered by tests
}
18 changes: 9 additions & 9 deletions eventloop_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

"github.com/panjf2000/gnet/v2/internal/io"
"github.com/panjf2000/gnet/v2/internal/netpoll"
gerrors "github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
"github.com/panjf2000/gnet/v2/pkg/logging"
)

Expand Down Expand Up @@ -115,7 +115,7 @@ func (el *eventloop) read(c *conn) error {
case Close:
return el.close(c, nil)
case Shutdown:
return gerrors.ErrEngineShutdown
return errorx.ErrEngineShutdown
}
_, _ = c.inboundBuffer.Write(c.buffer)
c.buffer = c.buffer[:0]
Expand Down Expand Up @@ -165,7 +165,7 @@ func (el *eventloop) close(c *conn, err error) (rerr error) {
el.connections.delConn(c)
}
if el.eventHandler.OnClose(c, err) == Shutdown {
return gerrors.ErrEngineShutdown
return errorx.ErrEngineShutdown
}
c.release()
return
Expand Down Expand Up @@ -206,7 +206,7 @@ func (el *eventloop) close(c *conn, err error) (rerr error) {

el.connections.delConn(c)
if el.eventHandler.OnClose(c, err) == Shutdown {
rerr = gerrors.ErrEngineShutdown
rerr = errorx.ErrEngineShutdown
}
c.release()

Expand Down Expand Up @@ -242,7 +242,7 @@ func (el *eventloop) ticker(ctx context.Context) {
switch action {
case None:
case Shutdown:
err := el.poller.UrgentTrigger(func(_ interface{}) error { return gerrors.ErrEngineShutdown }, nil)
err := el.poller.UrgentTrigger(func(_ interface{}) error { return errorx.ErrEngineShutdown }, nil)
el.getLogger().Debugf("stopping ticker in event-loop(%d) from OnTick(), UrgentTrigger:%v", el.idx, err)
}
if timer == nil {
Expand All @@ -266,7 +266,7 @@ func (el *eventloop) handleAction(c *conn, action Action) error {
case Close:
return el.close(c, nil)
case Shutdown:
return gerrors.ErrEngineShutdown
return errorx.ErrEngineShutdown
default:
return nil
}
Expand All @@ -293,7 +293,7 @@ func (el *eventloop) readUDP(fd int, _ netpoll.IOEvent) error {
c.release()
}
if action == Shutdown {
return gerrors.ErrEngineShutdown
return errorx.ErrEngineShutdown
}
return nil
}
Expand All @@ -303,7 +303,7 @@ func (el *eventloop) execCmd(itf interface{}) (err error) {
cmd := itf.(*asyncCmd)
c := el.connections.getConnByGFD(cmd.fd)
if c == nil || c.gfd != cmd.fd {
return gerrors.ErrInvalidConn
return errorx.ErrInvalidConn
}
defer func() {
Expand All @@ -322,7 +322,7 @@ func (el *eventloop) execCmd(itf interface{}) (err error) {
case asyncCmdWritev:
_, err = c.Writev(cmd.arg.([][]byte))
default:
return gerrors.ErrUnsupportedOp
return errorx.ErrUnsupportedOp
}
return
}
Expand Down
14 changes: 7 additions & 7 deletions gnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"go.uber.org/zap"
"golang.org/x/sync/errgroup"

gerr "github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
"github.com/panjf2000/gnet/v2/pkg/logging"
bbPool "github.com/panjf2000/gnet/v2/pkg/pool/bytebuffer"
goPool "github.com/panjf2000/gnet/v2/pkg/pool/goroutine"
Expand Down Expand Up @@ -814,8 +814,8 @@ func testShutdownActionOnOpen(t *testing.T, network, addr string) {
err := Run(events, network+"://"+addr, WithTicker(true))
assert.NoError(t, err)
_, err = events.eng.Dup()
assert.ErrorIsf(t, err, gerr.ErrEngineInShutdown, "expected error: %v, but got: %v",
gerr.ErrEngineInShutdown, err)
assert.ErrorIsf(t, err, errorx.ErrEngineInShutdown, "expected error: %v, but got: %v",
errorx.ErrEngineInShutdown, err)
}

func TestUDPShutdown(t *testing.T) {
Expand Down Expand Up @@ -887,7 +887,7 @@ func (t *testCloseConnectionServer) OnTraffic(c Conn) (action Action) {
go func() {
time.Sleep(time.Second)
_ = c.CloseWithCallback(func(c Conn, err error) error {
assert.ErrorIsf(t.tester, err, gerr.ErrEngineShutdown, "should be engine shutdown error")
assert.ErrorIsf(t.tester, err, errorx.ErrEngineShutdown, "should be engine shutdown error")
return nil
})
}()
Expand Down Expand Up @@ -923,7 +923,7 @@ func testCloseConnection(t *testing.T, network, addr string) {

func TestServerOptionsCheck(t *testing.T) {
err := Run(&BuiltinEventEngine{}, "tcp://:3500", WithNumEventLoop(10001), WithLockOSThread(true))
assert.EqualError(t, err, gerr.ErrTooManyEventLoopThreads.Error(), "error returned with LockOSThread option")
assert.EqualError(t, err, errorx.ErrTooManyEventLoopThreads.Error(), "error returned with LockOSThread option")
}

func TestStopServer(t *testing.T) {
Expand Down Expand Up @@ -1066,7 +1066,7 @@ func testEngineStop(t *testing.T, network, addr string) {
require.Greater(t, events2.exchngCount, int64(0))
require.Equal(t, int64(2+1+5+1), events1.exchngCount+events2.exchngCount)
// stop an already stopped engine
require.Equal(t, gerr.ErrEngineInShutdown, events1.eng.Stop(context.Background()))
require.Equal(t, errorx.ErrEngineInShutdown, events1.eng.Stop(context.Background()))
}

// Test should not panic when we wake-up server_closed conn.
Expand Down Expand Up @@ -1170,7 +1170,7 @@ func TestMultiInstLoggerRace(t *testing.T) {
return err
})

assert.ErrorIs(t, g.Wait(), gerr.ErrUnsupportedProtocol)
assert.ErrorIs(t, g.Wait(), errorx.ErrUnsupportedProtocol)
}

var errIncompletePacket = errors.New("incomplete packet")
Expand Down
4 changes: 2 additions & 2 deletions pkg/buffer/elastic/elastic_ring_list_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"math"

"github.com/panjf2000/gnet/v2/pkg/buffer/linkedlist"
gerrors "github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
)

// Buffer combines ring-buffer and list-buffer.
Expand All @@ -35,7 +35,7 @@ type Buffer struct {
// New instantiates an elastic.Buffer and returns it.
func New(maxStaticBytes int) (*Buffer, error) {
if maxStaticBytes <= 0 {
return nil, gerrors.ErrNegativeSize
return nil, errorx.ErrNegativeSize
}
return &Buffer{maxStaticBytes: maxStaticBytes}, nil
}
Expand Down

0 comments on commit 7699eae

Please sign in to comment.