optimize: uniform error creation (#668)

Co-authored-by: kinggo <lilong.21@bytedance.com>
This commit is contained in:
Lorain 2023-05-19 17:23:03 +08:00 committed by GitHub
parent 62aa1a0828
commit 062adad18a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 12 deletions

View File

@ -18,7 +18,6 @@ package server
import (
"context"
"errors"
"os"
"os/signal"
"syscall"
@ -26,6 +25,7 @@ import (
"github.com/cloudwego/hertz/pkg/app/middlewares/server/recovery"
"github.com/cloudwego/hertz/pkg/common/config"
"github.com/cloudwego/hertz/pkg/common/errors"
"github.com/cloudwego/hertz/pkg/common/hlog"
"github.com/cloudwego/hertz/pkg/route"
)
@ -108,7 +108,7 @@ func waitSignal(errCh chan error) error {
switch sig {
case syscall.SIGTERM:
// force exit
return errors.New(sig.String()) // nolint
return errors.NewPublic(sig.String()) // nolint
case syscall.SIGHUP, syscall.SIGINT:
hlog.SystemLogger().Infof("Received signal: %s\n", sig)
// graceful shutdown

View File

@ -42,11 +42,11 @@
package stackless
import (
"errors"
"fmt"
"io"
"github.com/cloudwego/hertz/pkg/common/bytebufferpool"
"github.com/cloudwego/hertz/pkg/common/errors"
)
// Writer is an interface stackless writer must conform to.
@ -137,7 +137,7 @@ func (w *writer) do(op op) error {
return err
}
var errHighLoad = errors.New("cannot compress data due to high load")
var errHighLoad = errors.NewPublic("cannot compress data due to high load")
var stacklessWriterFunc = NewFunc(writerFunc)

View File

@ -18,7 +18,6 @@ package mock
import (
"bytes"
"errors"
"net"
"strings"
"time"
@ -258,7 +257,7 @@ func (m *StreamConn) Peek(n int) ([]byte, error) {
m.Data = m.Data[:cap(m.Data)]
return m.Data[:1], nil
}
return nil, errors.New("not enough data")
return nil, errs.NewPublic("not enough data")
}
func (m *StreamConn) Skip(n int) error {
@ -266,7 +265,7 @@ func (m *StreamConn) Skip(n int) error {
m.Data = m.Data[n:]
return nil
}
return errors.New("not enough data")
return errs.NewPublic("not enough data")
}
func (m *StreamConn) Release() error {

View File

@ -17,9 +17,10 @@
package stats
import (
"errors"
"sync"
"sync/atomic"
"github.com/cloudwego/hertz/pkg/common/errors"
)
// EventIndex indicates a unique event.
@ -88,8 +89,8 @@ var (
// errors
var (
ErrNotAllowed = errors.New("event definition is not allowed after initialization")
ErrDuplicated = errors.New("event name is already defined")
ErrNotAllowed = errors.NewPublic("event definition is not allowed after initialization")
ErrDuplicated = errors.NewPublic("event name is already defined")
)
var (

View File

@ -28,11 +28,11 @@ import (
"context"
"crypto/tls"
"encoding/base64"
"errors"
"time"
"github.com/cloudwego/hertz/internal/bytesconv"
"github.com/cloudwego/hertz/internal/bytestr"
"github.com/cloudwego/hertz/pkg/common/errors"
"github.com/cloudwego/hertz/pkg/network"
"github.com/cloudwego/hertz/pkg/protocol"
"github.com/cloudwego/hertz/pkg/protocol/consts"
@ -111,7 +111,7 @@ func SetupProxy(conn network.Conn, addr string, proxyURI *protocol.URI, tlsConfi
if connectResp.StatusCode() != consts.StatusOK {
conn.Close()
return nil, errors.New(consts.StatusMessage(connectResp.StatusCode()))
return nil, errors.NewPublic(consts.StatusMessage(connectResp.StatusCode()))
}
}