mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 18:17:35 +00:00
refactor: rename package errors to zerrors (#7039)
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
This commit is contained in:
13
internal/cache/bigcache/bigcache_test.go
vendored
13
internal/cache/bigcache/bigcache_test.go
vendored
@@ -5,8 +5,9 @@ import (
|
||||
"testing"
|
||||
|
||||
a_cache "github.com/allegro/bigcache"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
|
||||
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type TestStruct struct {
|
||||
@@ -52,7 +53,7 @@ func TestSet(t *testing.T) {
|
||||
value: &TestStruct{Test: "Test"},
|
||||
},
|
||||
res: res{
|
||||
errFunc: errors.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -62,7 +63,7 @@ func TestSet(t *testing.T) {
|
||||
key: "KEY",
|
||||
},
|
||||
res: res{
|
||||
errFunc: errors.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -124,7 +125,7 @@ func TestGet(t *testing.T) {
|
||||
getValue: &TestStruct{Test: "Test"},
|
||||
},
|
||||
res: res{
|
||||
errFunc: errors.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -135,7 +136,7 @@ func TestGet(t *testing.T) {
|
||||
setValue: &TestStruct{Test: "Test"},
|
||||
},
|
||||
res: res{
|
||||
errFunc: errors.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -197,7 +198,7 @@ func TestDelete(t *testing.T) {
|
||||
getValue: &TestStruct{Test: "Test"},
|
||||
},
|
||||
res: res{
|
||||
errFunc: errors.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
15
internal/cache/bigcache/cache.go
vendored
15
internal/cache/bigcache/cache.go
vendored
@@ -7,7 +7,8 @@ import (
|
||||
|
||||
a_cache "github.com/allegro/bigcache"
|
||||
"github.com/zitadel/logging"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type Bigcache struct {
|
||||
@@ -29,27 +30,27 @@ func NewBigcache(c *Config) (*Bigcache, error) {
|
||||
|
||||
func (c *Bigcache) Set(key string, object interface{}) error {
|
||||
if key == "" || reflect.ValueOf(object).IsNil() {
|
||||
return errors.ThrowInvalidArgument(nil, "BIGCA-du73s", "key or value should not be empty")
|
||||
return zerrors.ThrowInvalidArgument(nil, "BIGCA-du73s", "key or value should not be empty")
|
||||
}
|
||||
var b bytes.Buffer
|
||||
enc := gob.NewEncoder(&b)
|
||||
if err := enc.Encode(object); err != nil {
|
||||
return errors.ThrowInvalidArgument(err, "BIGCA-RUyxI", "unable to encode object")
|
||||
return zerrors.ThrowInvalidArgument(err, "BIGCA-RUyxI", "unable to encode object")
|
||||
}
|
||||
return c.cache.Set(key, b.Bytes())
|
||||
}
|
||||
|
||||
func (c *Bigcache) Get(key string, ptrToObject interface{}) error {
|
||||
if key == "" || reflect.ValueOf(ptrToObject).IsNil() {
|
||||
return errors.ThrowInvalidArgument(nil, "BIGCA-dksoe", "key or value should not be empty")
|
||||
return zerrors.ThrowInvalidArgument(nil, "BIGCA-dksoe", "key or value should not be empty")
|
||||
}
|
||||
value, err := c.cache.Get(key)
|
||||
if err == a_cache.ErrEntryNotFound {
|
||||
return errors.ThrowNotFound(err, "BIGCA-we32s", "not in cache")
|
||||
return zerrors.ThrowNotFound(err, "BIGCA-we32s", "not in cache")
|
||||
}
|
||||
if err != nil {
|
||||
logging.Log("BIGCA-ftofbc").WithError(err).Info("read from cache failed")
|
||||
return errors.ThrowInvalidArgument(err, "BIGCA-3idls", "error in reading from cache")
|
||||
return zerrors.ThrowInvalidArgument(err, "BIGCA-3idls", "error in reading from cache")
|
||||
}
|
||||
|
||||
b := bytes.NewBuffer(value)
|
||||
@@ -60,7 +61,7 @@ func (c *Bigcache) Get(key string, ptrToObject interface{}) error {
|
||||
|
||||
func (c *Bigcache) Delete(key string) error {
|
||||
if key == "" {
|
||||
return errors.ThrowInvalidArgument(nil, "BIGCA-clsi2", "key should not be empty")
|
||||
return zerrors.ThrowInvalidArgument(nil, "BIGCA-clsi2", "key should not be empty")
|
||||
}
|
||||
return c.cache.Delete(key)
|
||||
}
|
||||
|
10
internal/cache/config/config.go
vendored
10
internal/cache/config/config.go
vendored
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/cache"
|
||||
"github.com/zitadel/zitadel/internal/cache/bigcache"
|
||||
"github.com/zitadel/zitadel/internal/cache/fastcache"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type CacheConfig struct {
|
||||
@@ -26,7 +26,7 @@ func (c *CacheConfig) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &rc); err != nil {
|
||||
return errors.ThrowInternal(err, "CONFI-98ejs", "unable to unmarshal config")
|
||||
return zerrors.ThrowInternal(err, "CONFI-98ejs", "unable to unmarshal config")
|
||||
}
|
||||
|
||||
c.Type = rc.Type
|
||||
@@ -34,7 +34,7 @@ func (c *CacheConfig) UnmarshalJSON(data []byte) error {
|
||||
var err error
|
||||
c.Config, err = newCacheConfig(c.Type, rc.Config)
|
||||
if err != nil {
|
||||
return errors.ThrowInternal(err, "CONFI-do9es", "unable create config")
|
||||
return zerrors.ThrowInternal(err, "CONFI-do9es", "unable create config")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -43,7 +43,7 @@ func (c *CacheConfig) UnmarshalJSON(data []byte) error {
|
||||
func newCacheConfig(cacheType string, configData []byte) (cache.Config, error) {
|
||||
t, ok := caches[cacheType]
|
||||
if !ok {
|
||||
return nil, errors.ThrowInternal(nil, "CONFI-di328s", "no config")
|
||||
return nil, zerrors.ThrowInternal(nil, "CONFI-di328s", "no config")
|
||||
}
|
||||
|
||||
cacheConfig := t()
|
||||
@@ -52,7 +52,7 @@ func newCacheConfig(cacheType string, configData []byte) (cache.Config, error) {
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(configData, cacheConfig); err != nil {
|
||||
return nil, errors.ThrowInternal(nil, "CONFI-skei3", "could not read config")
|
||||
return nil, zerrors.ThrowInternal(nil, "CONFI-skei3", "could not read config")
|
||||
}
|
||||
|
||||
return cacheConfig, nil
|
||||
|
14
internal/cache/fastcache/fastcache.go
vendored
14
internal/cache/fastcache/fastcache.go
vendored
@@ -5,9 +5,9 @@ import (
|
||||
"encoding/gob"
|
||||
"reflect"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
|
||||
"github.com/VictoriaMetrics/fastcache"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type Fastcache struct {
|
||||
@@ -22,12 +22,12 @@ func NewFastcache(config *Config) (*Fastcache, error) {
|
||||
|
||||
func (fc *Fastcache) Set(key string, object interface{}) error {
|
||||
if key == "" || reflect.ValueOf(object).IsNil() {
|
||||
return errors.ThrowInvalidArgument(nil, "FASTC-87dj3", "key or value should not be empty")
|
||||
return zerrors.ThrowInvalidArgument(nil, "FASTC-87dj3", "key or value should not be empty")
|
||||
}
|
||||
var b bytes.Buffer
|
||||
enc := gob.NewEncoder(&b)
|
||||
if err := enc.Encode(object); err != nil {
|
||||
return errors.ThrowInvalidArgument(err, "FASTC-RUyxI", "unable to encode object")
|
||||
return zerrors.ThrowInvalidArgument(err, "FASTC-RUyxI", "unable to encode object")
|
||||
}
|
||||
fc.cache.Set([]byte(key), b.Bytes())
|
||||
return nil
|
||||
@@ -35,11 +35,11 @@ func (fc *Fastcache) Set(key string, object interface{}) error {
|
||||
|
||||
func (fc *Fastcache) Get(key string, ptrToObject interface{}) error {
|
||||
if key == "" || reflect.ValueOf(ptrToObject).IsNil() {
|
||||
return errors.ThrowInvalidArgument(nil, "FASTC-di8es", "key or value should not be empty")
|
||||
return zerrors.ThrowInvalidArgument(nil, "FASTC-di8es", "key or value should not be empty")
|
||||
}
|
||||
data := fc.cache.Get(nil, []byte(key))
|
||||
if len(data) == 0 {
|
||||
return errors.ThrowNotFound(nil, "FASTC-xYzSm", "key not found")
|
||||
return zerrors.ThrowNotFound(nil, "FASTC-xYzSm", "key not found")
|
||||
}
|
||||
|
||||
b := bytes.NewBuffer(data)
|
||||
@@ -50,7 +50,7 @@ func (fc *Fastcache) Get(key string, ptrToObject interface{}) error {
|
||||
|
||||
func (fc *Fastcache) Delete(key string) error {
|
||||
if key == "" {
|
||||
return errors.ThrowInvalidArgument(nil, "FASTC-lod92", "key should not be empty")
|
||||
return zerrors.ThrowInvalidArgument(nil, "FASTC-lod92", "key should not be empty")
|
||||
}
|
||||
fc.cache.Del([]byte(key))
|
||||
return nil
|
||||
|
13
internal/cache/fastcache/fastcache_test.go
vendored
13
internal/cache/fastcache/fastcache_test.go
vendored
@@ -5,8 +5,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/VictoriaMetrics/fastcache"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
|
||||
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type TestStruct struct {
|
||||
@@ -47,7 +48,7 @@ func TestSet(t *testing.T) {
|
||||
value: &TestStruct{Test: "Test"},
|
||||
},
|
||||
res: res{
|
||||
errFunc: errors.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -57,7 +58,7 @@ func TestSet(t *testing.T) {
|
||||
key: "KEY",
|
||||
},
|
||||
res: res{
|
||||
errFunc: errors.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -119,7 +120,7 @@ func TestGet(t *testing.T) {
|
||||
getValue: &TestStruct{Test: "Test"},
|
||||
},
|
||||
res: res{
|
||||
errFunc: errors.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -130,7 +131,7 @@ func TestGet(t *testing.T) {
|
||||
setValue: &TestStruct{Test: "Test"},
|
||||
},
|
||||
res: res{
|
||||
errFunc: errors.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -192,7 +193,7 @@ func TestDelete(t *testing.T) {
|
||||
getValue: &TestStruct{Test: "Test"},
|
||||
},
|
||||
res: res{
|
||||
errFunc: errors.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user