mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +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:
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type SearchRequest interface {
|
||||
@@ -48,7 +48,7 @@ func PrepareSearchQuery(table string, request SearchRequest) func(db *gorm.DB, r
|
||||
var err error
|
||||
query, err = SetQuery(query, q.GetKey(), q.GetValue(), q.GetMethod())
|
||||
if err != nil {
|
||||
return count, caos_errs.ThrowInvalidArgument(err, "VIEW-KaGue", "query is invalid")
|
||||
return count, zerrors.ThrowInvalidArgument(err, "VIEW-KaGue", "query is invalid")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func PrepareSearchQuery(table string, request SearchRequest) func(db *gorm.DB, r
|
||||
query = query.Offset(request.GetOffset())
|
||||
err := query.Find(res).Error
|
||||
if err != nil {
|
||||
return count, caos_errs.ThrowInternal(err, "VIEW-muSDK", "unable to find result")
|
||||
return count, zerrors.ThrowInternal(err, "VIEW-muSDK", "unable to find result")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func PrepareSearchQuery(table string, request SearchRequest) func(db *gorm.DB, r
|
||||
func SetQuery(query *gorm.DB, key ColumnKey, value interface{}, method domain.SearchMethod) (*gorm.DB, error) {
|
||||
column := key.ToColumnName()
|
||||
if column == "" {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-7dz3w", "Column name missing")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "VIEW-7dz3w", "Column name missing")
|
||||
}
|
||||
|
||||
switch method {
|
||||
@@ -87,43 +87,43 @@ func SetQuery(query *gorm.DB, key ColumnKey, value interface{}, method domain.Se
|
||||
case domain.SearchMethodEqualsIgnoreCase:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-idu8e", "Equal ignore case only possible for strings")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "VIEW-idu8e", "Equal ignore case only possible for strings")
|
||||
}
|
||||
query = query.Where("LOWER("+column+") = LOWER(?)", valueText)
|
||||
case domain.SearchMethodStartsWith:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-SLj7s", "Starts with only possible for strings")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "VIEW-SLj7s", "Starts with only possible for strings")
|
||||
}
|
||||
query = query.Where(column+" LIKE ?", valueText+"%")
|
||||
case domain.SearchMethodStartsWithIgnoreCase:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-eidus", "Starts with ignore case only possible for strings")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "VIEW-eidus", "Starts with ignore case only possible for strings")
|
||||
}
|
||||
query = query.Where("LOWER("+column+") LIKE LOWER(?)", valueText+"%")
|
||||
case domain.SearchMethodEndsWith:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-Hswd3", "Ends with only possible for strings")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "VIEW-Hswd3", "Ends with only possible for strings")
|
||||
}
|
||||
query = query.Where(column+" LIKE ?", "%"+valueText)
|
||||
case domain.SearchMethodEndsWithIgnoreCase:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-dAG31", "Ends with ignore case only possible for strings")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "VIEW-dAG31", "Ends with ignore case only possible for strings")
|
||||
}
|
||||
query = query.Where("LOWER("+column+") LIKE LOWER(?)", "%"+valueText)
|
||||
case domain.SearchMethodContains:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-3ids", "Contains with only possible for strings")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "VIEW-3ids", "Contains with only possible for strings")
|
||||
}
|
||||
query = query.Where(column+" LIKE ?", "%"+valueText+"%")
|
||||
case domain.SearchMethodContainsIgnoreCase:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-eid73", "Contains with ignore case only possible for strings")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "VIEW-eid73", "Contains with ignore case only possible for strings")
|
||||
}
|
||||
query = query.Where("LOWER("+column+") LIKE LOWER(?)", "%"+valueText+"%")
|
||||
case domain.SearchMethodNotEquals:
|
||||
@@ -137,7 +137,7 @@ func SetQuery(query *gorm.DB, key ColumnKey, value interface{}, method domain.Se
|
||||
case domain.SearchMethodListContains:
|
||||
valueText, ok := value.(string)
|
||||
if !ok {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "VIEW-Psois", "list contains only possible for strings")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "VIEW-Psois", "list contains only possible for strings")
|
||||
}
|
||||
query = query.Where("? <@ "+column, database.TextArray[string]{valueText})
|
||||
default:
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func TestPrepareSearchQuery(t *testing.T) {
|
||||
@@ -126,7 +126,7 @@ func TestPrepareSearchQuery(t *testing.T) {
|
||||
res{
|
||||
count: 1,
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsInternal,
|
||||
errFunc: zerrors.IsInternal,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@@ -9,8 +9,7 @@ import (
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func PrepareGetByQuery(table string, queries ...SearchQuery) func(db *gorm.DB, res interface{}) error {
|
||||
@@ -20,7 +19,7 @@ func PrepareGetByQuery(table string, queries ...SearchQuery) func(db *gorm.DB, r
|
||||
var err error
|
||||
query, err = SetQuery(query, q.GetKey(), q.GetValue(), q.GetMethod())
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInvalidArgument(err, "VIEW-KaGue", "query is invalid")
|
||||
return zerrors.ThrowInvalidArgument(err, "VIEW-KaGue", "query is invalid")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +35,10 @@ func PrepareGetByQuery(table string, queries ...SearchQuery) func(db *gorm.DB, r
|
||||
return nil
|
||||
}
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return caos_errs.ThrowNotFound(err, "VIEW-hodc6", "object not found")
|
||||
return zerrors.ThrowNotFound(err, "VIEW-hodc6", "object not found")
|
||||
}
|
||||
logging.LogWithFields("VIEW-Mg6la", "table ", table).WithError(err).Warn("get from cache error")
|
||||
return caos_errs.ThrowInternal(err, "VIEW-qJBg9", "cache error")
|
||||
return zerrors.ThrowInternal(err, "VIEW-qJBg9", "cache error")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,16 +47,16 @@ func PrepareBulkSave(table string) func(db *gorm.DB, objects ...interface{}) err
|
||||
db = db.Table(table)
|
||||
db = db.Begin()
|
||||
if err := db.Error; err != nil {
|
||||
return caos_errs.ThrowInternal(err, "REPOS-Fl0Is", "unable to begin")
|
||||
return zerrors.ThrowInternal(err, "REPOS-Fl0Is", "unable to begin")
|
||||
}
|
||||
for _, object := range objects {
|
||||
err := db.Save(object).Error
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "VIEW-oJJSm", "unable to put object to view")
|
||||
return zerrors.ThrowInternal(err, "VIEW-oJJSm", "unable to put object to view")
|
||||
}
|
||||
}
|
||||
if err := db.Commit().Error; err != nil {
|
||||
return caos_errs.ThrowInternal(err, "REPOS-IfhUE", "unable to commit")
|
||||
return zerrors.ThrowInternal(err, "REPOS-IfhUE", "unable to commit")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -67,7 +66,7 @@ func PrepareSave(table string) func(db *gorm.DB, object interface{}) error {
|
||||
return func(db *gorm.DB, object interface{}) error {
|
||||
err := db.Table(table).Save(object).Error
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "VIEW-2m9fs", "unable to put object to view")
|
||||
return zerrors.ThrowInternal(err, "VIEW-2m9fs", "unable to put object to view")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -82,7 +81,7 @@ func PrepareSaveOnConflict(table string, conflictColumns, updateColumns []string
|
||||
return func(db *gorm.DB, object interface{}) error {
|
||||
err := db.Table(table).Set("gorm:insert_option", onConflict).Save(object).Error
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "VIEW-AfC7G", "unable to put object to view")
|
||||
return zerrors.ThrowInternal(err, "VIEW-AfC7G", "unable to put object to view")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -95,7 +94,7 @@ func PrepareDeleteByKey(table string, key ColumnKey, id interface{}) func(db *go
|
||||
Delete(nil).
|
||||
Error
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "VIEW-die73", "could not delete object")
|
||||
return zerrors.ThrowInternal(err, "VIEW-die73", "could not delete object")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -111,7 +110,7 @@ func PrepareUpdateByKeys(table string, column ColumnKey, value interface{}, keys
|
||||
Update(column.ToColumnName(), value).
|
||||
Error
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "VIEW-ps099xj", "could not update object")
|
||||
return zerrors.ThrowInternal(err, "VIEW-ps099xj", "could not update object")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -132,7 +131,7 @@ func PrepareDeleteByKeys(table string, keys ...Key) func(db *gorm.DB) error {
|
||||
Delete(nil).
|
||||
Error
|
||||
if err != nil {
|
||||
return caos_errs.ThrowInternal(err, "VIEW-die73", "could not delete object")
|
||||
return zerrors.ThrowInternal(err, "VIEW-die73", "could not delete object")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func TestPrepareGetByQuery(t *testing.T) {
|
||||
@@ -114,7 +114,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsNotFound,
|
||||
errFunc: zerrors.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -128,7 +128,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsInternal,
|
||||
errFunc: zerrors.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -142,7 +142,7 @@ func TestPrepareGetByQuery(t *testing.T) {
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsErrorInvalidArgument,
|
||||
errFunc: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -212,7 +212,7 @@ func TestPreparePut(t *testing.T) {
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsInternal,
|
||||
errFunc: zerrors.IsInternal,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -284,7 +284,7 @@ func TestPrepareDelete(t *testing.T) {
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsInternal,
|
||||
errFunc: zerrors.IsInternal,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -375,7 +375,7 @@ func TestPrepareDeleteByKeys(t *testing.T) {
|
||||
res{
|
||||
result: Test{ID: "VALUE"},
|
||||
wantErr: true,
|
||||
errFunc: caos_errs.IsInternal,
|
||||
errFunc: zerrors.IsInternal,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user