mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37:32 +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:
@@ -4,8 +4,8 @@ import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
// SearchQuery defines the which and how data are queried
|
||||
@@ -99,16 +99,16 @@ func NewFilter(field Field, value interface{}, operation Operation) *Filter {
|
||||
// Validate checks if the fields of the filter have valid values
|
||||
func (f *Filter) Validate() error {
|
||||
if f == nil {
|
||||
return errors.ThrowPreconditionFailed(nil, "REPO-z6KcG", "filter is nil")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "REPO-z6KcG", "filter is nil")
|
||||
}
|
||||
if f.Field <= 0 || f.Field >= fieldCount {
|
||||
return errors.ThrowPreconditionFailed(nil, "REPO-zw62U", "field not definded")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "REPO-zw62U", "field not definded")
|
||||
}
|
||||
if f.Value == nil {
|
||||
return errors.ThrowPreconditionFailed(nil, "REPO-GJ9ct", "no value definded")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "REPO-GJ9ct", "no value definded")
|
||||
}
|
||||
if f.Operation <= 0 || f.Operation >= operationCount {
|
||||
return errors.ThrowPreconditionFailed(nil, "REPO-RrQTy", "operation not definded")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "REPO-RrQTy", "operation not definded")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func (f *Filter) Validate() error {
|
||||
func QueryFromBuilder(builder *eventstore.SearchQueryBuilder) (*SearchQuery, error) {
|
||||
if builder == nil ||
|
||||
builder.GetColumns().Validate() != nil {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "MODEL-4m9gs", "builder invalid")
|
||||
return nil, zerrors.ThrowPreconditionFailed(nil, "MODEL-4m9gs", "builder invalid")
|
||||
}
|
||||
|
||||
query := &SearchQuery{
|
||||
|
@@ -16,9 +16,9 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -189,7 +189,7 @@ func (db *CRDB) Push(ctx context.Context, commands ...eventstore.Command) (event
|
||||
"eventType", e.Type(),
|
||||
"instanceID", e.Aggregate().InstanceID,
|
||||
).WithError(err).Debug("query failed")
|
||||
return caos_errs.ThrowInternal(err, "SQL-SBP37", "unable to create event")
|
||||
return zerrors.ThrowInternal(err, "SQL-SBP37", "unable to create event")
|
||||
}
|
||||
|
||||
uniqueConstraints = append(uniqueConstraints, command.UniqueConstraints()...)
|
||||
@@ -198,8 +198,8 @@ func (db *CRDB) Push(ctx context.Context, commands ...eventstore.Command) (event
|
||||
|
||||
return db.handleUniqueConstraints(ctx, tx, uniqueConstraints...)
|
||||
})
|
||||
if err != nil && !errors.Is(err, &caos_errs.CaosError{}) {
|
||||
err = caos_errs.ThrowInternal(err, "SQL-DjgtG", "unable to store events")
|
||||
if err != nil && !errors.Is(err, &zerrors.ZitadelError{}) {
|
||||
err = zerrors.ThrowInternal(err, "SQL-DjgtG", "unable to store events")
|
||||
}
|
||||
|
||||
return events, err
|
||||
@@ -222,10 +222,10 @@ func (db *CRDB) handleUniqueConstraints(ctx context.Context, tx *sql.Tx, uniqueC
|
||||
"unique_field", uniqueConstraint.UniqueField).WithError(err).Info("insert unique constraint failed")
|
||||
|
||||
if db.isUniqueViolationError(err) {
|
||||
return caos_errs.ThrowAlreadyExists(err, "SQL-wHcEq", uniqueConstraint.ErrorMessage)
|
||||
return zerrors.ThrowAlreadyExists(err, "SQL-wHcEq", uniqueConstraint.ErrorMessage)
|
||||
}
|
||||
|
||||
return caos_errs.ThrowInternal(err, "SQL-dM9ds", "unable to create unique constraint")
|
||||
return zerrors.ThrowInternal(err, "SQL-dM9ds", "unable to create unique constraint")
|
||||
}
|
||||
case eventstore.UniqueConstraintRemove:
|
||||
_, err := tx.ExecContext(ctx, uniqueDelete, uniqueConstraint.UniqueType, uniqueConstraint.UniqueField, authz.GetInstance(ctx).InstanceID())
|
||||
@@ -233,14 +233,14 @@ func (db *CRDB) handleUniqueConstraints(ctx context.Context, tx *sql.Tx, uniqueC
|
||||
logging.WithFields(
|
||||
"unique_type", uniqueConstraint.UniqueType,
|
||||
"unique_field", uniqueConstraint.UniqueField).WithError(err).Info("delete unique constraint failed")
|
||||
return caos_errs.ThrowInternal(err, "SQL-6n88i", "unable to remove unique constraint")
|
||||
return zerrors.ThrowInternal(err, "SQL-6n88i", "unable to remove unique constraint")
|
||||
}
|
||||
case eventstore.UniqueConstraintInstanceRemove:
|
||||
_, err := tx.ExecContext(ctx, uniqueDeleteInstance, authz.GetInstance(ctx).InstanceID())
|
||||
if err != nil {
|
||||
logging.WithFields(
|
||||
"instance_id", authz.GetInstance(ctx).InstanceID()).WithError(err).Info("delete instance unique constraints failed")
|
||||
return caos_errs.ThrowInternal(err, "SQL-6n88i", "unable to remove unique constraints of instance")
|
||||
return zerrors.ThrowInternal(err, "SQL-6n88i", "unable to remove unique constraints of instance")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,9 +14,9 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/api/call"
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/database/dialect"
|
||||
z_errors "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type querier interface {
|
||||
@@ -62,7 +62,7 @@ func query(ctx context.Context, criteria querier, searchQuery *eventstore.Search
|
||||
query, rowScanner := prepareColumns(criteria, q.Columns, useV1)
|
||||
where, values := prepareConditions(criteria, q, useV1)
|
||||
if where == "" || query == "" {
|
||||
return z_errors.ThrowInvalidArgument(nil, "SQL-rWeBw", "invalid query factory")
|
||||
return zerrors.ThrowInvalidArgument(nil, "SQL-rWeBw", "invalid query factory")
|
||||
}
|
||||
if q.Tx == nil {
|
||||
if travel := prepareTimeTravel(ctx, criteria, q.AllowTimeTravel); travel != "" {
|
||||
@@ -116,7 +116,7 @@ func query(ctx context.Context, criteria querier, searchQuery *eventstore.Search
|
||||
}, query, values...)
|
||||
if err != nil {
|
||||
logging.New().WithError(err).Info("query failed")
|
||||
return z_errors.ThrowInternal(err, "SQL-KyeAx", "unable to filter events")
|
||||
return zerrors.ThrowInternal(err, "SQL-KyeAx", "unable to filter events")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -146,25 +146,25 @@ func prepareTimeTravel(ctx context.Context, criteria querier, allow bool) string
|
||||
func maxSequenceScanner(row scan, dest interface{}) (err error) {
|
||||
position, ok := dest.(*sql.NullFloat64)
|
||||
if !ok {
|
||||
return z_errors.ThrowInvalidArgumentf(nil, "SQL-NBjA9", "type must be sql.NullInt64 got: %T", dest)
|
||||
return zerrors.ThrowInvalidArgumentf(nil, "SQL-NBjA9", "type must be sql.NullInt64 got: %T", dest)
|
||||
}
|
||||
err = row(position)
|
||||
if err == nil || errors.Is(err, sql.ErrNoRows) {
|
||||
return nil
|
||||
}
|
||||
return z_errors.ThrowInternal(err, "SQL-bN5xg", "something went wrong")
|
||||
return zerrors.ThrowInternal(err, "SQL-bN5xg", "something went wrong")
|
||||
}
|
||||
|
||||
func instanceIDsScanner(scanner scan, dest interface{}) (err error) {
|
||||
ids, ok := dest.(*[]string)
|
||||
if !ok {
|
||||
return z_errors.ThrowInvalidArgument(nil, "SQL-Begh2", "type must be an array of string")
|
||||
return zerrors.ThrowInvalidArgument(nil, "SQL-Begh2", "type must be an array of string")
|
||||
}
|
||||
var id string
|
||||
err = scanner(&id)
|
||||
if err != nil {
|
||||
logging.WithError(err).Warn("unable to scan row")
|
||||
return z_errors.ThrowInternal(err, "SQL-DEFGe", "unable to scan row")
|
||||
return zerrors.ThrowInternal(err, "SQL-DEFGe", "unable to scan row")
|
||||
}
|
||||
*ids = append(*ids, id)
|
||||
|
||||
@@ -175,7 +175,7 @@ func eventsScanner(useV1 bool) func(scanner scan, dest interface{}) (err error)
|
||||
return func(scanner scan, dest interface{}) (err error) {
|
||||
reduce, ok := dest.(eventstore.Reducer)
|
||||
if !ok {
|
||||
return z_errors.ThrowInvalidArgumentf(nil, "SQL-4GP6F", "events scanner: invalid type %T", dest)
|
||||
return zerrors.ThrowInvalidArgumentf(nil, "SQL-4GP6F", "events scanner: invalid type %T", dest)
|
||||
}
|
||||
event := new(repository.Event)
|
||||
position := new(sql.NullFloat64)
|
||||
@@ -213,7 +213,7 @@ func eventsScanner(useV1 bool) func(scanner scan, dest interface{}) (err error)
|
||||
|
||||
if err != nil {
|
||||
logging.New().WithError(err).Warn("unable to scan row")
|
||||
return z_errors.ThrowInternal(err, "SQL-M0dsf", "unable to scan row")
|
||||
return zerrors.ThrowInternal(err, "SQL-M0dsf", "unable to scan row")
|
||||
}
|
||||
event.Pos = position.Float64
|
||||
return reduce(event)
|
||||
|
@@ -14,9 +14,9 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/database/cockroach"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func Test_getCondition(t *testing.T) {
|
||||
@@ -142,7 +142,7 @@ func Test_prepareColumns(t *testing.T) {
|
||||
},
|
||||
res: res{
|
||||
query: `SELECT "position" FROM eventstore.events2`,
|
||||
dbErr: errors.IsErrorInvalidArgument,
|
||||
dbErr: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -212,7 +212,7 @@ func Test_prepareColumns(t *testing.T) {
|
||||
},
|
||||
res: res{
|
||||
query: `SELECT creation_date, event_type, event_sequence, event_data, editor_user, resource_owner, instance_id, aggregate_type, aggregate_id, aggregate_version FROM eventstore.events`,
|
||||
dbErr: errors.IsErrorInvalidArgument,
|
||||
dbErr: zerrors.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -228,7 +228,7 @@ func Test_prepareColumns(t *testing.T) {
|
||||
},
|
||||
res: res{
|
||||
query: `SELECT creation_date, event_type, event_sequence, event_data, editor_user, resource_owner, instance_id, aggregate_type, aggregate_id, aggregate_version FROM eventstore.events`,
|
||||
dbErr: errors.IsInternal,
|
||||
dbErr: zerrors.IsInternal,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -277,7 +277,7 @@ func prepareTestScan(err error, res []interface{}) scan {
|
||||
return err
|
||||
}
|
||||
if len(dests) != len(res) {
|
||||
return errors.ThrowInvalidArgumentf(nil, "SQL-NML1q", "expected len %d got %d", len(res), len(dests))
|
||||
return zerrors.ThrowInvalidArgumentf(nil, "SQL-NML1q", "expected len %d got %d", len(res), len(dests))
|
||||
}
|
||||
for i, r := range res {
|
||||
_, ok := dests[i].(*eventstore.Version)
|
||||
|
Reference in New Issue
Block a user