From 22f5dd3937da41315456b617b01414e8bbaa4b3d Mon Sep 17 00:00:00 2001 From: Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:08:26 +0800 Subject: [PATCH] refactor: replace errors into errs. --- go.mod | 2 -- go.sum | 15 ----------- internal/api/route.go | 4 +-- internal/msggateway/client.go | 13 +++++----- internal/msggateway/long_conn.go | 4 +-- internal/msggateway/n_ws_server.go | 15 ++--------- internal/msgtransfer/init.go | 3 +-- internal/push/offlinepush/getui/push.go | 5 ++-- .../push/offlinepush/jpush/body/platform.go | 8 +++--- internal/push/push_to_client.go | 4 +-- internal/rpc/conversation/conversaion.go | 8 +----- internal/rpc/group/super_group.go | 6 ++--- internal/rpc/third/tool.go | 7 +++-- internal/rpc/user/user.go | 3 +-- pkg/common/cmd/rpc.go | 6 ++--- pkg/common/db/cache/conversation.go | 26 +------------------ pkg/common/db/cache/meta_cache.go | 3 +-- pkg/common/db/controller/msg.go | 5 ++-- pkg/common/db/table/relation/msg.go | 3 +-- .../discoveryregister/direct/directconn.go | 5 ++-- .../discoveryregister/discoveryregister.go | 4 +-- pkg/localcache/lru/lru_lazy_test.go | 7 +---- tools/url2im/pkg/api.go | 3 +-- 23 files changed, 38 insertions(+), 121 deletions(-) diff --git a/go.mod b/go.mod index 55bfb6173..d73aea17e 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/openimsdk/open-im-server/v3 go 1.21 -toolchain go1.21.8 - require ( firebase.google.com/go v3.13.0+incompatible github.com/dtm-labs/rockscache v0.1.1 diff --git a/go.sum b/go.sum index 0ba17e372..33eee89ff 100644 --- a/go.sum +++ b/go.sum @@ -22,13 +22,10 @@ github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mo github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g= github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= -github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= -github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= -github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= @@ -46,7 +43,6 @@ github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5P github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/PB79y4KOPYVyFYdROxgaCwdTQ= -github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -69,11 +65,9 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v1.0.4 h1:gVPz/FMfvh57HdSJQyvBtF00j8JU4zdyUgIUNhlgg0A= -github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZH4Blx/1gTIZ2UKVY1M+Yew= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= -github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -89,7 +83,6 @@ github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ4 github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= -github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= @@ -143,7 +136,6 @@ github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian/v3 v3.3.2 h1:IqNFLAmvJOgVlpdEBiQbDc2EwKW77amAycfTuWKdfvw= -github.com/google/martian/v3 v3.3.2/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= @@ -194,7 +186,6 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4= -github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -206,7 +197,6 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -285,7 +275,6 @@ github.com/redis/go-redis/v9 v9.4.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0 github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -341,13 +330,11 @@ go.opentelemetry.io/otel v1.23.0/go.mod h1:YCycw9ZeKhcJFrb34iVSkyT0iczq/zYDtZYFu go.opentelemetry.io/otel/metric v1.23.0 h1:pazkx7ss4LFVVYSxYew7L5I6qvLXHA0Ap2pwV+9Cnpo= go.opentelemetry.io/otel/metric v1.23.0/go.mod h1:MqUW2X2a6Q8RN96E2/nqNoT+z9BSms20Jb7Bbp+HiTo= go.opentelemetry.io/otel/sdk v1.21.0 h1:FTt8qirL1EysG6sTQRZ5TokkU8d0ugCj8htOgThZXQ8= -go.opentelemetry.io/otel/sdk v1.21.0/go.mod h1:Nna6Yv7PWTdgJHVRD9hIYywQBRx7pbox6nwBnZIxl/E= go.opentelemetry.io/otel/trace v1.23.0 h1:37Ik5Ib7xfYVb4V1UtnT97T1jI+AoIYkJyPkuL4iJgI= go.opentelemetry.io/otel/trace v1.23.0/go.mod h1:GSGTbIClEsuZrGIzoEHqsVfxgn5UkggkflQwDScNUsk= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= -go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= @@ -450,7 +437,6 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= -golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= google.golang.org/api v0.165.0 h1:zd5d4JIIIaYYsfVy1HzoXYZ9rWCSBxxAglbczzo7Bgc= google.golang.org/api v0.165.0/go.mod h1:2OatzO7ZDQsoS7IFf3rvsE17/TldiU3F/zxFHeqUB5o= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= @@ -488,7 +474,6 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/internal/api/route.go b/internal/api/route.go index d584c517e..766a199b9 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -16,7 +16,6 @@ package api import ( "context" - "errors" "fmt" "github.com/openimsdk/tools/db/redisutil" "net" @@ -54,8 +53,7 @@ import ( func Start(ctx context.Context, config *config.GlobalConfig, port int, proPort int) error { if port == 0 || proPort == 0 { - wrappedErr := errs.WrapMsg(errors.New("port or proPort is empty"), "validation error", "port", port, "proPort", proPort) - return wrappedErr + return errs.New("port or proPort is empty", "port", port, "proPort", proPort).Wrap() } rdb, err := redisutil.NewRedisClient(ctx, config.Redis.Build()) if err != nil { diff --git a/internal/msggateway/client.go b/internal/msggateway/client.go index 26f1c3dc8..8be20ce9c 100644 --- a/internal/msggateway/client.go +++ b/internal/msggateway/client.go @@ -16,7 +16,6 @@ package msggateway import ( "context" - "errors" "fmt" "runtime/debug" "sync" @@ -34,10 +33,10 @@ import ( ) var ( - ErrConnClosed = errors.New("conn has closed") - ErrNotSupportMessageProtocol = errors.New("not support message protocol") - ErrClientClosed = errors.New("client actively close the connection") - ErrPanic = errors.New("panic error") + ErrConnClosed = errs.New("conn has closed") + ErrNotSupportMessageProtocol = errs.New("not support message protocol") + ErrClientClosed = errs.New("client actively close the connection") + ErrPanic = errs.New("panic error") ) const ( @@ -187,7 +186,7 @@ func (c *Client) handleMessage(message []byte) error { } if binaryReq.SendID != c.UserID { - return errs.WrapMsg(errors.New("exception conn userID not same to req userID"), binaryReq.String()) + return errs.New("exception conn userID not same to req userID", "binaryReq", binaryReq.String()) } ctx := mcontext.WithMustInfoCtx( @@ -267,7 +266,7 @@ func (c *Client) replyMessage(ctx context.Context, binaryReq *Req, err error, re } if binaryReq.ReqIdentifier == WsLogoutMsg { - return errs.WrapMsg(errors.New("user logout"), "user requested logout", "operationID", binaryReq.OperationID) + return errs.New("user logout", "operationID", binaryReq.OperationID).Wrap() } return nil } diff --git a/internal/msggateway/long_conn.go b/internal/msggateway/long_conn.go index 51ad27497..dfd5e2e87 100644 --- a/internal/msggateway/long_conn.go +++ b/internal/msggateway/long_conn.go @@ -15,7 +15,6 @@ package msggateway import ( - "errors" "net/http" "time" @@ -99,9 +98,8 @@ func (d *GWebSocket) SetReadDeadline(timeout time.Duration) error { } func (d *GWebSocket) SetWriteDeadline(timeout time.Duration) error { - // TODO add error if timeout <= 0 { - return errs.Wrap(errors.New("timeout must be greater than 0")) + return errs.New("timeout must be greater than 0") } // TODO SetWriteDeadline Future add error handling diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go index e07913627..526ea628c 100644 --- a/internal/msggateway/n_ws_server.go +++ b/internal/msggateway/n_ws_server.go @@ -17,7 +17,6 @@ package msggateway import ( "context" "encoding/json" - "errors" "fmt" "net/http" "strconv" @@ -59,13 +58,6 @@ type LongConnServer interface { MessageHandler } -// bufferPool is unused -// var bufferPool = sync.Pool{ -// New: func() any { -// return make([]byte, 1024) -// }, -// } - type WsServer struct { globalConfig *config.GlobalConfig port int @@ -128,10 +120,7 @@ func (ws *WsServer) UnRegister(c *Client) { ws.unregisterChan <- c } -func (ws *WsServer) Validate(s any) error { - if s == nil { - return errs.WrapMsg(errors.New("input cannot be nil"), "Validate: input is nil", "action", "validate", "dataType", "any") - } +func (ws *WsServer) Validate(_ any) error { return nil } @@ -372,7 +361,7 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien log.ZWarn( newClient.ctx, "m is nil", - errors.New("m is nil"), + errs.New("m is nil"), "userID", newClient.UserID, "platformID", diff --git a/internal/msgtransfer/init.go b/internal/msgtransfer/init.go index 71db7c859..9c185b2e1 100644 --- a/internal/msgtransfer/init.go +++ b/internal/msgtransfer/init.go @@ -16,7 +16,6 @@ package msgtransfer import ( "context" - "errors" "fmt" "github.com/openimsdk/tools/db/mongoutil" "github.com/openimsdk/tools/db/redisutil" @@ -114,7 +113,7 @@ func NewMsgTransfer(kafkaConf *config.Kafka, msgDatabase controller.CommonMsgDat func (m *MsgTransfer) Start(prometheusPort int, config *config.GlobalConfig, index int) error { if prometheusPort <= 0 { - return errs.WrapMsg(errors.New("invalid prometheus port"), "prometheusPort validation failed", "providedPort", prometheusPort) + return errs.New("invalid prometheus port", "prometheusPort", prometheusPort) } m.ctx, m.cancel = context.WithCancel(context.Background()) diff --git a/internal/push/offlinepush/getui/push.go b/internal/push/offlinepush/getui/push.go index 74bf07f07..644a6c449 100644 --- a/internal/push/offlinepush/getui/push.go +++ b/internal/push/offlinepush/getui/push.go @@ -18,7 +18,6 @@ import ( "context" "crypto/sha256" "encoding/hex" - "errors" "strconv" "sync" "time" @@ -35,8 +34,8 @@ import ( ) var ( - ErrTokenExpire = errors.New("token expire") - ErrUserIDEmpty = errors.New("userIDs is empty") + ErrTokenExpire = errs.New("token expire") + ErrUserIDEmpty = errs.New("userIDs is empty") ) const ( diff --git a/internal/push/offlinepush/jpush/body/platform.go b/internal/push/offlinepush/jpush/body/platform.go index b66397cca..5654165fa 100644 --- a/internal/push/offlinepush/jpush/body/platform.go +++ b/internal/push/offlinepush/jpush/body/platform.go @@ -15,7 +15,7 @@ package body import ( - "errors" + "github.com/openimsdk/tools/errs" "github.com/openimsdk/protocol/constant" ) @@ -39,7 +39,7 @@ func (p *Platform) Set(os string) error { } else { switch p.Os.(type) { case string: - return errors.New("platform is all") + return errs.New("platform is all") default: } } @@ -61,7 +61,7 @@ func (p *Platform) Set(os string) error { p.osArry = append(p.osArry, os) p.Os = p.osArry default: - return errors.New("unknow platform") + return errs.New("unknow platform") } return nil @@ -74,7 +74,7 @@ func (p *Platform) SetPlatform(platform string) error { case constant.IOSPlatformStr: return p.SetIOS() default: - return errors.New("platform err") + return errs.New("platform err") } } diff --git a/internal/push/push_to_client.go b/internal/push/push_to_client.go index b53fd23a2..cf69fb13d 100644 --- a/internal/push/push_to_client.go +++ b/internal/push/push_to_client.go @@ -17,7 +17,7 @@ package push import ( "context" "encoding/json" - "errors" + "github.com/openimsdk/tools/errs" "sync" "github.com/openimsdk/open-im-server/v3/internal/push/offlinepush" @@ -59,7 +59,7 @@ type Pusher struct { groupRpcClient *rpcclient.GroupRpcClient } -var errNoOfflinePusher = errors.New("no offlinePusher is configured") +var errNoOfflinePusher = errs.New("no offlinePusher is configured") func NewPusher(config *config.GlobalConfig, discov discovery.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase, groupLocalCache *rpccache.GroupLocalCache, conversationLocalCache *rpccache.ConversationLocalCache, diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index 3ef0236af..6de9bcfc1 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -16,7 +16,6 @@ package conversation import ( "context" - "errors" "github.com/openimsdk/tools/db/redisutil" "sort" @@ -315,12 +314,7 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver // Get user IDs with "Do Not Disturb" enabled in super large groups. func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req *pbconversation.GetRecvMsgNotNotifyUserIDsReq) (*pbconversation.GetRecvMsgNotNotifyUserIDsResp, error) { - // userIDs, err := c.conversationDatabase.FindRecvMsgNotNotifyUserIDs(ctx, req.GroupID) - // if err != nil { - // return nil, err - //} - // return &pbconversation.GetRecvMsgNotNotifyUserIDsResp{UserIDs: userIDs}, nil - return nil, errors.New("deprecated") + return nil, errs.New("deprecated") } // create conversation without notification for msg redis transfer. diff --git a/internal/rpc/group/super_group.go b/internal/rpc/group/super_group.go index 469a5066c..3f8f998d5 100644 --- a/internal/rpc/group/super_group.go +++ b/internal/rpc/group/super_group.go @@ -16,16 +16,14 @@ package group import ( "context" - "errors" - pbgroup "github.com/openimsdk/protocol/group" "github.com/openimsdk/tools/errs" ) func (s *groupServer) GetJoinedSuperGroupList(context.Context, *pbgroup.GetJoinedSuperGroupListReq) (*pbgroup.GetJoinedSuperGroupListResp, error) { - return nil, errs.WrapMsg(errors.New("GetJoinedSuperGroupList is deprecated"), "This feature is deprecated and no longer supported.") + return nil, errs.New("GetJoinedSuperGroupList is deprecated").Wrap() } func (s *groupServer) GetSuperGroupsInfo(context.Context, *pbgroup.GetSuperGroupsInfoReq) (resp *pbgroup.GetSuperGroupsInfoResp, err error) { - return nil, errs.WrapMsg(errors.New("GetSuperGroupsInfo is deprecated"), "This feature is deprecated and no longer supported.") + return nil, errs.New("GetSuperGroupsInfo is deprecated").Wrap() } diff --git a/internal/rpc/third/tool.go b/internal/rpc/third/tool.go index cab301e1e..0d8c678b3 100644 --- a/internal/rpc/third/tool.go +++ b/internal/rpc/third/tool.go @@ -16,7 +16,6 @@ package third import ( "context" - "errors" "fmt" "strings" "unicode/utf8" @@ -65,17 +64,17 @@ func (t *thirdServer) checkUploadName(ctx context.Context, name string) error { func checkValidObjectNamePrefix(objectName string) error { if len(objectName) > 1024 { - return errors.New("object name cannot be longer than 1024 characters") + return errs.New("object name cannot be longer than 1024 characters") } if !utf8.ValidString(objectName) { - return errors.New("object name with non UTF-8 strings are not supported") + return errs.New("object name with non UTF-8 strings are not supported") } return nil } func checkValidObjectName(objectName string) error { if strings.TrimSpace(objectName) == "" { - return errors.New("object name cannot be empty") + return errs.New("object name cannot be empty") } return checkValidObjectNamePrefix(objectName) } diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 48bbea285..955d66ad5 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -16,7 +16,6 @@ package user import ( "context" - "errors" "github.com/openimsdk/tools/db/redisutil" "math/rand" "strings" @@ -71,7 +70,7 @@ func Start(ctx context.Context, config *config.GlobalConfig, client registry.Svc } users := make([]*tablerelation.UserModel, 0) if len(config.IMAdmin.UserID) != len(config.IMAdmin.Nickname) { - return errs.Wrap(errors.New("the count of ImAdmin.UserID is not equal to the count of ImAdmin.Nickname")) + return errs.New("the count of ImAdmin.UserID is not equal to the count of ImAdmin.Nickname").Wrap() } for k, v := range config.IMAdmin.UserID { users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.IMAdmin.Nickname[k], AppMangerLevel: constant.AppNotificationAdmin}) diff --git a/pkg/common/cmd/rpc.go b/pkg/common/cmd/rpc.go index c8446eb6b..e550708ed 100644 --- a/pkg/common/cmd/rpc.go +++ b/pkg/common/cmd/rpc.go @@ -16,8 +16,6 @@ package cmd import ( "context" - "errors" - config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config" "github.com/openimsdk/open-im-server/v3/pkg/common/startrpc" "github.com/openimsdk/protocol/constant" @@ -70,7 +68,7 @@ func (a *RpcCmd) Exec() error { func (a *RpcCmd) StartSvr(name string, rpcFn func(ctx context.Context, config *config2.GlobalConfig, disCov discovery.SvcDiscoveryRegistry, server *grpc.Server) error) error { if a.GetPortFlag() == 0 { - return errs.Wrap(errors.New("port is required")) + return errs.New("port is required").Wrap() } return startrpc.Start(a.ctx, a.GetPortFlag(), name, a.GetPrometheusPortFlag(), a.config, rpcFn) } @@ -156,5 +154,5 @@ func (a *RpcCmd) GetRpcRegisterNameFromConfig() (string, error) { case RpcUserServer: return a.config.RpcRegisterName.OpenImUserName, nil } - return "", errs.WrapMsg(errors.New("unrecognized RPC server name"), "providedName", a.Name, "hint", "Check if the server name is correctly configured") + return "", errs.New("unrecognized RPC server name", "rpcName", a.Name).Wrap() } diff --git a/pkg/common/db/cache/conversation.go b/pkg/common/db/cache/conversation.go index 3a075ab9c..21a9a30fc 100644 --- a/pkg/common/db/cache/conversation.go +++ b/pkg/common/db/cache/conversation.go @@ -233,7 +233,7 @@ func (c *ConversationRedisCache) DelConversations(ownerUserID string, conversati // } // } -// return 0, errors.New("not found key:" + key + " in keys") +// return 0, errs.New("not found key:" + key + " in keys") // } func (c *ConversationRedisCache) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationtb.ConversationModel, error) { @@ -338,30 +338,6 @@ func (c *ConversationRedisCache) DelSuperGroupRecvMsgNotNotifyUserIDsHash(groupI return cache } -/* func (c *ConversationRedisCache) getUserAllHasReadSeqsIndex(conversationID string, conversationIDs []string) (int, error) { - for _i, _conversationID := range conversationIDs { - if _conversationID == conversationID { - return _i, nil - } - } - - return 0, errors.New("not found key:" + conversationID + " in keys") -} */ - -/* func (c *ConversationRedisCache) GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (map[string]int64, error) { - conversationIDs, err := c.GetUserConversationIDs(ctx, ownerUserID) - if err != nil { - return nil, err - } - var keys []string - for _, conversarionID := range conversationIDs { - keys = append(keys, c.getConversationHasReadSeqKey(ownerUserID, conversarionID)) - } - return batchGetCacheMap(ctx, c.rcClient, keys, conversationIDs, c.expireTime, c.getUserAllHasReadSeqsIndex, func(ctx context.Context) (map[string]int64, error) { - return c.conversationDB.GetUserAllHasReadSeqs(ctx, ownerUserID) - }) -} */ - func (c *ConversationRedisCache) DelUserAllHasReadSeqs(ownerUserID string, conversationIDs ...string) ConversationCache { cache := c.NewCache() for _, conversationID := range conversationIDs { diff --git a/pkg/common/db/cache/meta_cache.go b/pkg/common/db/cache/meta_cache.go index 6a9f6fe88..e633e4fbd 100644 --- a/pkg/common/db/cache/meta_cache.go +++ b/pkg/common/db/cache/meta_cache.go @@ -17,7 +17,6 @@ package cache import ( "context" "encoding/json" - "errors" "fmt" "time" @@ -35,7 +34,7 @@ const ( retryInterval = time.Millisecond * 100 ) -var errIndex = errors.New("err index") +var errIndex = errs.New("err index") type metaCache interface { ExecDel(ctx context.Context, distinct ...bool) error diff --git a/pkg/common/db/controller/msg.go b/pkg/common/db/controller/msg.go index 959a20096..7a6a2fc02 100644 --- a/pkg/common/db/controller/msg.go +++ b/pkg/common/db/controller/msg.go @@ -17,7 +17,6 @@ package controller import ( "context" "encoding/json" - "errors" "time" "github.com/openimsdk/open-im-server/v3/pkg/common/config" @@ -363,10 +362,10 @@ func (db *commonMsgDatabase) BatchInsertChat2Cache(ctx context.Context, conversa } lenList := len(msgs) if int64(lenList) > db.msg.GetSingleGocMsgNum() { - return 0, false, errs.WrapMsg(errors.New("message count exceeds limit"), "limit", db.msg.GetSingleGocMsgNum()) + return 0, false, errs.New("message count exceeds limit", "limit", db.msg.GetSingleGocMsgNum()).Wrap() } if lenList < 1 { - return 0, false, errs.WrapMsg(errors.New("no messages to insert"), "minCount", 1) + return 0, false, errs.New("no messages to insert", "minCount", 1).Wrap() } if errs.Unwrap(err) == redis.Nil { isNew = true diff --git a/pkg/common/db/table/relation/msg.go b/pkg/common/db/table/relation/msg.go index eb1e2444f..fcdaf3299 100644 --- a/pkg/common/db/table/relation/msg.go +++ b/pkg/common/db/table/relation/msg.go @@ -16,7 +16,6 @@ package relation import ( "context" - "errors" "strconv" "time" @@ -33,7 +32,7 @@ const ( NewestList = -1 ) -var ErrMsgListNotExist = errors.New("user not have msg in mongoDB") +var ErrMsgListNotExist = errs.New("user not have msg in mongoDB") type MsgDocModel struct { DocID string `bson:"doc_id"` diff --git a/pkg/common/discoveryregister/direct/directconn.go b/pkg/common/discoveryregister/direct/directconn.go index c5ecd0ad5..024638730 100644 --- a/pkg/common/discoveryregister/direct/directconn.go +++ b/pkg/common/discoveryregister/direct/directconn.go @@ -16,7 +16,6 @@ package direct import ( "context" - "errors" "fmt" config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config" @@ -108,7 +107,7 @@ func (cd *ConnDirect) GetConns(ctx context.Context, } if len(connections) == 0 { - return nil, errs.WrapMsg(errors.New("no connections found for service"), "serviceName", serviceName) + return nil, errs.New("no connections found for service", "serviceName", serviceName).Wrap() } return connections, nil } @@ -119,7 +118,7 @@ func (cd *ConnDirect) GetConn(ctx context.Context, serviceName string, opts ...g &cd.config.RpcPort, cd.config.LongConnSvr.OpenImMessageGatewayPort) address, ok := addresses[serviceName] if !ok { - return nil, errs.WrapMsg(errors.New("unknown service name"), "serviceName", serviceName) + return nil, errs.New("unknown service name", "serviceName", serviceName).Wrap() } var result string for _, addr := range address { diff --git a/pkg/common/discoveryregister/discoveryregister.go b/pkg/common/discoveryregister/discoveryregister.go index 90546e54a..fdebd79cc 100644 --- a/pkg/common/discoveryregister/discoveryregister.go +++ b/pkg/common/discoveryregister/discoveryregister.go @@ -15,7 +15,6 @@ package discoveryregister import ( - "errors" "os" "github.com/openimsdk/open-im-server/v3/pkg/common/config" @@ -41,7 +40,6 @@ func NewDiscoveryRegister(config *config.GlobalConfig) (discovery.SvcDiscoveryRe case "direct": return direct.NewConnDirect(config) default: - errMsg := "unsupported discovery type" - return nil, errs.WrapMsg(errors.New(errMsg), errMsg, "type", config.Envs.Discovery) + return nil, errs.New("unsupported discovery type", "type", config.Envs.Discovery).Wrap() } } diff --git a/pkg/localcache/lru/lru_lazy_test.go b/pkg/localcache/lru/lru_lazy_test.go index 167dd2135..ab0fa50a0 100644 --- a/pkg/localcache/lru/lru_lazy_test.go +++ b/pkg/localcache/lru/lru_lazy_test.go @@ -92,12 +92,7 @@ func TestName(t *testing.T) { defer wg.Done() //t.Log(key) fn(key, 10000, func() (string, error) { - //time.Sleep(time.Second * 3) - //t.Log(time.Now(), "key", key, "fetch") - //if rand.Uint32()%5 == 0 { - // return "value_" + key, nil - //} - //return "", errors.New("rand error") + return "value_" + key, nil }) }() diff --git a/tools/url2im/pkg/api.go b/tools/url2im/pkg/api.go index 64a89b9ab..cd7ce7027 100644 --- a/tools/url2im/pkg/api.go +++ b/tools/url2im/pkg/api.go @@ -18,7 +18,6 @@ import ( "bytes" "context" "encoding/json" - "errors" "fmt" "io" "net/http" @@ -39,7 +38,7 @@ type Api struct { func (a *Api) apiPost(ctx context.Context, path string, req any, resp any) error { operationID, _ := ctx.Value("operationID").(string) if operationID == "" { - return errors.New("call api operationID is empty") + return errs.New("call api operationID is empty") } reqBody, err := json.Marshal(req) if err != nil {