mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:37:31 +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:
@@ -5,7 +5,7 @@ import (
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type action interface {
|
||||
@@ -63,7 +63,7 @@ func EventData(event Command) ([]byte, error) {
|
||||
if json.Valid(data) {
|
||||
return data, nil
|
||||
}
|
||||
return nil, errors.ThrowInvalidArgument(nil, "V2-6SbbS", "data bytes are not json")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "V2-6SbbS", "data bytes are not json")
|
||||
}
|
||||
dataType := reflect.TypeOf(event.Payload())
|
||||
if dataType.Kind() == reflect.Ptr {
|
||||
@@ -72,11 +72,11 @@ func EventData(event Command) ([]byte, error) {
|
||||
if dataType.Kind() == reflect.Struct {
|
||||
dataBytes, err := json.Marshal(event.Payload())
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "V2-xG87M", "could not marshal data")
|
||||
return nil, zerrors.ThrowInvalidArgument(err, "V2-xG87M", "could not marshal data")
|
||||
}
|
||||
return dataBytes, nil
|
||||
}
|
||||
return nil, errors.ThrowInvalidArgument(nil, "V2-91NRm", "wrong type of event data")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "V2-91NRm", "wrong type of event data")
|
||||
}
|
||||
|
||||
type BaseEventSetter[T any] interface {
|
||||
@@ -91,7 +91,7 @@ func GenericEventMapper[T any, PT BaseEventSetter[T]](event Event) (Event, error
|
||||
|
||||
err := event.Unmarshal(e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "ES-Thai6", "unable to unmarshal event")
|
||||
return nil, zerrors.ThrowInternal(err, "ES-Thai6", "unable to unmarshal event")
|
||||
}
|
||||
|
||||
return e, nil
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/api/service"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
// testEvent implements the Event interface
|
||||
@@ -122,7 +122,7 @@ func Test_eventstore_RegisterFilterEventMapper(t *testing.T) {
|
||||
eventMapper: map[EventType]eventTypeInterceptors{
|
||||
"event.type": {
|
||||
eventMapper: func(Event) (Event, error) {
|
||||
return nil, errors.ThrowUnimplemented(nil, "V2-1qPvn", "unimplemented")
|
||||
return nil, zerrors.ThrowUnimplemented(nil, "V2-1qPvn", "unimplemented")
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -661,7 +661,7 @@ func TestEventstore_Push(t *testing.T) {
|
||||
fields: fields{
|
||||
pusher: &testPusher{
|
||||
t: t,
|
||||
err: errors.ThrowInternal(nil, "V2-qaa4S", "test err"),
|
||||
err: zerrors.ThrowInternal(nil, "V2-qaa4S", "test err"),
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -684,7 +684,7 @@ func TestEventstore_Push(t *testing.T) {
|
||||
fields: fields{
|
||||
pusher: &testPusher{
|
||||
t: t,
|
||||
err: errors.ThrowInternal(nil, "V2-qaa4S", "test err"),
|
||||
err: zerrors.ThrowInternal(nil, "V2-qaa4S", "test err"),
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -775,7 +775,7 @@ func TestEventstore_FilterEvents(t *testing.T) {
|
||||
fields: fields{
|
||||
repo: &testQuerier{
|
||||
t: t,
|
||||
err: errors.ThrowInternal(nil, "V2-RfkBa", "test err"),
|
||||
err: zerrors.ThrowInternal(nil, "V2-RfkBa", "test err"),
|
||||
},
|
||||
eventMapper: map[EventType]func(Event) (Event, error){
|
||||
"test.event": func(e Event) (Event, error) {
|
||||
@@ -901,7 +901,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
|
||||
fields: fields{
|
||||
repo: &testQuerier{
|
||||
t: t,
|
||||
err: errors.ThrowInternal(nil, "V2-RfkBa", "test err"),
|
||||
err: zerrors.ThrowInternal(nil, "V2-RfkBa", "test err"),
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
@@ -1038,7 +1038,7 @@ func TestEventstore_FilterToReducer(t *testing.T) {
|
||||
fields: fields{
|
||||
repo: &testQuerier{
|
||||
t: t,
|
||||
err: errors.ThrowInternal(nil, "V2-RfkBa", "test err"),
|
||||
err: zerrors.ThrowInternal(nil, "V2-RfkBa", "test err"),
|
||||
},
|
||||
eventMapper: map[EventType]func(Event) (Event, error){
|
||||
"test.event": func(e Event) (Event, error) {
|
||||
@@ -1100,7 +1100,7 @@ func TestEventstore_FilterToReducer(t *testing.T) {
|
||||
},
|
||||
readModel: &testReducer{
|
||||
t: t,
|
||||
err: errors.ThrowInvalidArgument(nil, "V2-W06TG", "test err"),
|
||||
err: zerrors.ThrowInvalidArgument(nil, "V2-W06TG", "test err"),
|
||||
expectedLength: 1,
|
||||
},
|
||||
},
|
||||
@@ -1212,7 +1212,7 @@ func TestEventstore_mapEvents(t *testing.T) {
|
||||
fields: fields{
|
||||
eventMapper: map[EventType]func(Event) (Event, error){
|
||||
"test.event": func(Event) (Event, error) {
|
||||
return nil, errors.ThrowInternal(nil, "V2-8FbQk", "test err")
|
||||
return nil, zerrors.ThrowInternal(nil, "V2-8FbQk", "test err")
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/id"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -74,10 +74,10 @@ func (h *locker) renewLock(ctx context.Context, lockDuration time.Duration, inst
|
||||
lockStmt, values := h.lockStatement(lockDuration, instanceIDs)
|
||||
res, err := h.client.ExecContext(ctx, lockStmt, values...)
|
||||
if err != nil {
|
||||
return errors.ThrowInternal(err, "CRDB-uaDoR", "unable to execute lock")
|
||||
return zerrors.ThrowInternal(err, "CRDB-uaDoR", "unable to execute lock")
|
||||
}
|
||||
if rows, _ := res.RowsAffected(); rows == 0 {
|
||||
return errors.ThrowAlreadyExists(nil, "CRDB-mmi4J", "projection already locked")
|
||||
return zerrors.ThrowAlreadyExists(nil, "CRDB-mmi4J", "projection already locked")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func (h *locker) Unlock(instanceIDs ...string) error {
|
||||
lockStmt, values := h.lockStatement(0, instanceIDs)
|
||||
_, err := h.client.Exec(lockStmt, values...)
|
||||
if err != nil {
|
||||
return errors.ThrowUnknown(err, "CRDB-JjfwO", "unlock failed")
|
||||
return zerrors.ThrowUnknown(err, "CRDB-JjfwO", "unlock failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
z_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -21,7 +21,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
renewNoRowsAffectedErr = z_errs.ThrowAlreadyExists(nil, "CRDB-mmi4J", "projection already locked")
|
||||
renewNoRowsAffectedErr = zerrors.ThrowAlreadyExists(nil, "CRDB-mmi4J", "projection already locked")
|
||||
errLock = errors.New("lock err")
|
||||
)
|
||||
|
||||
|
@@ -5,8 +5,8 @@ import (
|
||||
_ "embed"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -69,10 +69,10 @@ func (h *Handler) failureCount(tx *sql.Tx, f *failure) (count uint8, err error)
|
||||
f.sequence,
|
||||
)
|
||||
if err = row.Err(); err != nil {
|
||||
return 0, errors.ThrowInternal(err, "CRDB-Unnex", "unable to update failure count")
|
||||
return 0, zerrors.ThrowInternal(err, "CRDB-Unnex", "unable to update failure count")
|
||||
}
|
||||
if err = row.Scan(&count); err != nil {
|
||||
return 0, errors.ThrowInternal(err, "CRDB-RwSMV", "unable to scan count")
|
||||
return 0, zerrors.ThrowInternal(err, "CRDB-RwSMV", "unable to scan count")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func (h *Handler) setFailureCount(tx *sql.Tx, count uint8, f *failure) error {
|
||||
f.err.Error(),
|
||||
)
|
||||
if err != nil {
|
||||
return errors.ThrowInternal(err, "CRDB-4Ht4x", "set failure count failed")
|
||||
return zerrors.ThrowInternal(err, "CRDB-4Ht4x", "set failure count failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/jackc/pgconn"
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type Table struct {
|
||||
@@ -196,7 +196,7 @@ func (h *Handler) Init(ctx context.Context) error {
|
||||
}
|
||||
tx, err := h.client.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return errs.ThrowInternal(err, "CRDB-SAdf2", "begin failed")
|
||||
return zerrors.ThrowInternal(err, "CRDB-SAdf2", "begin failed")
|
||||
}
|
||||
for i, execute := range check.Init().Executes {
|
||||
logging.WithFields("projection", h.projection.Name(), "execute", i).Debug("executing check")
|
||||
@@ -274,7 +274,7 @@ func execNextIfExists(config execConfig, q query, opts []execOption, executeNext
|
||||
}
|
||||
|
||||
func isErrAlreadyExists(err error) bool {
|
||||
caosErr := &errs.CaosError{}
|
||||
caosErr := &zerrors.ZitadelError{}
|
||||
if !errors.As(err, &caosErr) {
|
||||
return false
|
||||
}
|
||||
|
@@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type state struct {
|
||||
@@ -97,7 +97,7 @@ func (h *Handler) setState(tx *sql.Tx, updatedState *state) error {
|
||||
}
|
||||
if affected, err := res.RowsAffected(); affected == 0 {
|
||||
h.log().OnError(err).Error("unable to check if states are updated")
|
||||
return errs.ThrowInternal(err, "V2-FGEKi", "unable to update state")
|
||||
return zerrors.ThrowInternal(err, "V2-FGEKi", "unable to update state")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (h *Handler) lockState(tx *sql.Tx, instanceID string) error {
|
||||
return err
|
||||
}
|
||||
if affected, err := res.RowsAffected(); affected == 0 || err != nil {
|
||||
return errs.ThrowInternal(err, "V2-lpiK0", "projection already locked")
|
||||
return zerrors.ThrowInternal(err, "V2-lpiK0", "projection already locked")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/database/mock"
|
||||
errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func TestHandler_lockState(t *testing.T) {
|
||||
@@ -80,7 +80,7 @@ func TestHandler_lockState(t *testing.T) {
|
||||
instanceID: "instance",
|
||||
},
|
||||
isErr: func(t *testing.T, err error) {
|
||||
if !errors.Is(err, errs.ThrowInternal(nil, "V2-lpiK0", "")) {
|
||||
if !errors.Is(err, zerrors.ThrowInternal(nil, "V2-lpiK0", "")) {
|
||||
t.Errorf("unexpected error: want internal (V2lpiK0), got: %v", err)
|
||||
}
|
||||
},
|
||||
@@ -195,7 +195,7 @@ func TestHandler_updateLastUpdated(t *testing.T) {
|
||||
},
|
||||
},
|
||||
isErr: func(t *testing.T, err error) {
|
||||
if !errors.Is(err, errs.ThrowInternal(nil, "V2-FGEKi", "")) {
|
||||
if !errors.Is(err, zerrors.ThrowInternal(nil, "V2-FGEKi", "")) {
|
||||
t.Errorf("unexpected error, want: %v, got %v", sql.ErrTxDone, err)
|
||||
}
|
||||
},
|
||||
|
@@ -3,7 +3,7 @@ package handler
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
errs "errors"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func (h *Handler) eventsToStatements(tx *sql.Tx, events []eventstore.Event, currentState *state) (statements []*Statement, err error) {
|
||||
@@ -79,9 +79,9 @@ func WithTableSuffix(name string) func(*execConfig) {
|
||||
}
|
||||
|
||||
var (
|
||||
ErrNoProjection = errs.New("no projection")
|
||||
ErrNoValues = errs.New("no values")
|
||||
ErrNoCondition = errs.New("no condition")
|
||||
ErrNoProjection = errors.New("no projection")
|
||||
ErrNoValues = errors.New("no values")
|
||||
ErrNoCondition = errors.New("no condition")
|
||||
)
|
||||
|
||||
func NewStatement(event eventstore.Event, e Exec) *Statement {
|
||||
@@ -558,7 +558,7 @@ func exec(config execConfig, q query, opts []execOption) Exec {
|
||||
|
||||
_, err = ex.Exec("SAVEPOINT stmt_exec")
|
||||
if err != nil {
|
||||
return errors.ThrowInternal(err, "CRDB-YdOXD", "create savepoint failed")
|
||||
return zerrors.ThrowInternal(err, "CRDB-YdOXD", "create savepoint failed")
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
@@ -570,7 +570,7 @@ func exec(config execConfig, q query, opts []execOption) Exec {
|
||||
}()
|
||||
_, err = ex.Exec(q(config), config.args...)
|
||||
if err != nil {
|
||||
return errors.ThrowInternal(err, "CRDB-pKtsr", "exec failed")
|
||||
return zerrors.ThrowInternal(err, "CRDB-pKtsr", "exec failed")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -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)
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
// SearchQueryBuilder represents the builder for your filter
|
||||
@@ -141,7 +141,7 @@ const (
|
||||
|
||||
func (c Columns) Validate() error {
|
||||
if c <= 0 || c >= columnsCount {
|
||||
return errors.ThrowPreconditionFailed(nil, "REPOS-x8R35", "column out of range")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "REPOS-x8R35", "column out of range")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -5,8 +5,8 @@ import (
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type EventType string
|
||||
@@ -101,7 +101,7 @@ func eventData(i interface{}) ([]byte, error) {
|
||||
case map[string]interface{}:
|
||||
bytes, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "MODEL-s2fgE", "unable to marshal data")
|
||||
return nil, zerrors.ThrowInvalidArgument(err, "MODEL-s2fgE", "unable to marshal data")
|
||||
}
|
||||
return bytes, nil
|
||||
case nil:
|
||||
@@ -112,11 +112,11 @@ func eventData(i interface{}) ([]byte, error) {
|
||||
t = t.Elem()
|
||||
}
|
||||
if t.Kind() != reflect.Struct {
|
||||
return nil, errors.ThrowInvalidArgument(nil, "MODEL-rjWdN", "data is not valid")
|
||||
return nil, zerrors.ThrowInvalidArgument(nil, "MODEL-rjWdN", "data is not valid")
|
||||
}
|
||||
bytes, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInvalidArgument(err, "MODEL-Y2OpM", "unable to marshal data")
|
||||
return nil, zerrors.ThrowInvalidArgument(err, "MODEL-Y2OpM", "unable to marshal data")
|
||||
}
|
||||
return bytes, nil
|
||||
}
|
||||
@@ -124,29 +124,29 @@ func eventData(i interface{}) ([]byte, error) {
|
||||
|
||||
func (e *Event) Validate() error {
|
||||
if e == nil {
|
||||
return errors.ThrowPreconditionFailed(nil, "MODEL-oEAG4", "event is nil")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "MODEL-oEAG4", "event is nil")
|
||||
}
|
||||
if string(e.Typ) == "" {
|
||||
return errors.ThrowPreconditionFailed(nil, "MODEL-R2sB0", "type not defined")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "MODEL-R2sB0", "type not defined")
|
||||
}
|
||||
|
||||
if e.AggregateID == "" {
|
||||
return errors.ThrowPreconditionFailed(nil, "MODEL-A6WwL", "aggregate id not set")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "MODEL-A6WwL", "aggregate id not set")
|
||||
}
|
||||
if e.AggregateType == "" {
|
||||
return errors.ThrowPreconditionFailed(nil, "MODEL-EzdyK", "aggregate type not set")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "MODEL-EzdyK", "aggregate type not set")
|
||||
}
|
||||
if err := e.AggregateVersion.Validate(); err != nil {
|
||||
return errors.ThrowPreconditionFailed(err, "MODEL-KO71q", "version invalid")
|
||||
return zerrors.ThrowPreconditionFailed(err, "MODEL-KO71q", "version invalid")
|
||||
}
|
||||
if e.Service == "" {
|
||||
return errors.ThrowPreconditionFailed(nil, "MODEL-4Yqik", "editor service not set")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "MODEL-4Yqik", "editor service not set")
|
||||
}
|
||||
if e.User == "" {
|
||||
return errors.ThrowPreconditionFailed(nil, "MODEL-L3NHO", "editor user not set")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "MODEL-L3NHO", "editor user not set")
|
||||
}
|
||||
if e.ResourceOwner == "" {
|
||||
return errors.ThrowPreconditionFailed(nil, "MODEL-omFVT", "resource ow")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "MODEL-omFVT", "resource ow")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -31,7 +31,7 @@ func commandToEvent(sequence *latestSequence, command eventstore.Command) (_ *ev
|
||||
payload, err = json.Marshal(command.Payload())
|
||||
if err != nil {
|
||||
logging.WithError(err).Warn("marshal payload failed")
|
||||
return nil, errors.ThrowInternal(err, "V3-MInPK", "Errors.Internal")
|
||||
return nil, zerrors.ThrowInternal(err, "V3-MInPK", "Errors.Internal")
|
||||
}
|
||||
}
|
||||
return &event{
|
||||
@@ -95,7 +95,7 @@ func (e *event) Unmarshal(ptr any) error {
|
||||
return nil
|
||||
}
|
||||
if err := json.Unmarshal(e.payload, ptr); err != nil {
|
||||
return errors.ThrowInternal(err, "V3-u8qVo", "Errors.Internal")
|
||||
return zerrors.ThrowInternal(err, "V3-u8qVo", "Errors.Internal")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
_ "embed"
|
||||
errs "errors"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
"github.com/jackc/pgconn"
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func (es *Eventstore) Push(ctx context.Context, commands ...eventstore.Command) (events []eventstore.Event, err error) {
|
||||
@@ -77,16 +77,16 @@ func insertEvents(ctx context.Context, tx *sql.Tx, sequences []*latestSequence,
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
pgErr := new(pgconn.PgError)
|
||||
if errs.As(err, &pgErr) {
|
||||
if errors.As(err, &pgErr) {
|
||||
// Check if push tries to write an event just written
|
||||
// by another transaction
|
||||
if pgErr.Code == "40001" {
|
||||
// TODO: @livio-a should we return the parent or not?
|
||||
return nil, errors.ThrowInvalidArgument(err, "V3-p5xAn", "Errors.AlreadyExists")
|
||||
return nil, zerrors.ThrowInvalidArgument(err, "V3-p5xAn", "Errors.AlreadyExists")
|
||||
}
|
||||
}
|
||||
logging.WithError(rows.Err()).Warn("failed to push events")
|
||||
return nil, errors.ThrowInternal(err, "V3-VGnZY", "Errors.Internal")
|
||||
return nil, zerrors.ThrowInternal(err, "V3-VGnZY", "Errors.Internal")
|
||||
}
|
||||
|
||||
return events, nil
|
||||
@@ -132,7 +132,7 @@ func mapCommands(commands []eventstore.Command, sequences []*latestSequence) (ev
|
||||
|
||||
revision, err := strconv.Atoi(strings.TrimPrefix(string(events[i].(*event).aggregate.Version), "v"))
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.ThrowInternal(err, "V3-JoZEp", "Errors.Internal")
|
||||
return nil, nil, nil, zerrors.ThrowInternal(err, "V3-JoZEp", "Errors.Internal")
|
||||
}
|
||||
args = append(args,
|
||||
events[i].(*event).aggregate.InstanceID,
|
||||
|
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type latestSequence struct {
|
||||
@@ -28,18 +28,18 @@ func latestSequences(ctx context.Context, tx *sql.Tx, commands []eventstore.Comm
|
||||
conditions, args := sequencesToSql(sequences)
|
||||
rows, err := tx.QueryContext(ctx, fmt.Sprintf(latestSequencesStmt, strings.Join(conditions, " OR ")), args...)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "V3-5jU5z", "Errors.Internal")
|
||||
return nil, zerrors.ThrowInternal(err, "V3-5jU5z", "Errors.Internal")
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
if err := scanToSequence(rows, sequences); err != nil {
|
||||
return nil, errors.ThrowInternal(err, "V3-Ydiwv", "Errors.Internal")
|
||||
return nil, zerrors.ThrowInternal(err, "V3-Ydiwv", "Errors.Internal")
|
||||
}
|
||||
}
|
||||
|
||||
if rows.Err() != nil {
|
||||
return nil, errors.ThrowInternal(rows.Err(), "V3-XApDk", "Errors.Internal")
|
||||
return nil, zerrors.ThrowInternal(rows.Err(), "V3-XApDk", "Errors.Internal")
|
||||
}
|
||||
return sequences, nil
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func scanToSequence(rows *sql.Rows, sequences []*latestSequence) error {
|
||||
var resourceOwner string
|
||||
|
||||
if err := rows.Scan(&instanceID, &resourceOwner, &aggregateType, &aggregateID, ¤tSequence); err != nil {
|
||||
return errors.ThrowInternal(err, "V3-OIWqj", "Errors.Internal")
|
||||
return zerrors.ThrowInternal(err, "V3-OIWqj", "Errors.Internal")
|
||||
}
|
||||
|
||||
sequence := searchSequence(sequences, aggregateType, aggregateID, instanceID)
|
||||
|
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/jackc/pgconn"
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -61,7 +61,7 @@ func handleUniqueConstraints(ctx context.Context, tx *sql.Tx, commands []eventst
|
||||
if constraint := constraintFromErr(err, deleteConstraints); constraint != nil {
|
||||
errMessage = constraint.ErrorMessage
|
||||
}
|
||||
return errs.ThrowInternal(err, "V3-C8l3V", errMessage)
|
||||
return zerrors.ThrowInternal(err, "V3-C8l3V", errMessage)
|
||||
}
|
||||
}
|
||||
if len(addPlaceholders) > 0 {
|
||||
@@ -72,7 +72,7 @@ func handleUniqueConstraints(ctx context.Context, tx *sql.Tx, commands []eventst
|
||||
if constraint := constraintFromErr(err, addConstraints); constraint != nil {
|
||||
errMessage = constraint.ErrorMessage
|
||||
}
|
||||
return errs.ThrowAlreadyExists(err, "V3-DKcYh", errMessage)
|
||||
return zerrors.ThrowAlreadyExists(err, "V3-DKcYh", errMessage)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@@ -3,7 +3,7 @@ package eventstore
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type Version string
|
||||
@@ -12,7 +12,7 @@ var versionRegexp = regexp.MustCompile(`^v[0-9]+(\.[0-9]+){0,2}$`)
|
||||
|
||||
func (v Version) Validate() error {
|
||||
if !versionRegexp.MatchString(string(v)) {
|
||||
return errors.ThrowPreconditionFailed(nil, "MODEL-luDuS", "version is not semver")
|
||||
return zerrors.ThrowPreconditionFailed(nil, "MODEL-luDuS", "version is not semver")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user