feat(domain): introduce error slugs (#12030)

# Which Problems Are Solved

As part of https://github.com/zitadel/zitadel/issues/11917 we want to
introduce error slugs so (API) clients can rely on stable,
machine-readable errors and act accordingly.

# How the Problems Are Solved

- Added a `NewSlug` helper function in the domain package.
- Added `ErrorDetails` to the `ZitadelError`
- Added an `zitadel.error.v2.ErrorDetail` proto message
- Updated the connectRPC error interceptor to map new slug based errors
to the new `ErrorDetail`
- Defined some common slugs and error functions like internal errors
- Defined (session) specific slugs used in the `DeleteSession` and
`CheckUser` functions and replaced old implementations
- Updated integration tests to check specific errors if the relation
database feature is enabled
- Updated doc and guideline to reflect the latest changes and decisions
- Updated DeleteSession endpoint API to list possible slugs

# Additional Changes

None

# Additional Context

- closes #11957

---------

Co-authored-by: Wim Van Laer <[email protected]>
This commit is contained in:
Livio Spring
2026-04-13 09:47:04 +02:00
committed by GitHub
co-authored by Wim Van Laer
parent 5c9361f6c7
commit a2bf528ca0
18 changed files with 524 additions and 97 deletions
+16 -14
View File
@@ -82,13 +82,13 @@ func (u *UserCheckCommand) Execute(ctx context.Context, opts *InvokeOpts) (err e
session, err := sessionRepo.Get(ctx, opts.DB(), database.WithCondition(sessionRepo.IDCondition(u.SessionID)))
if err != nil {
if errors.Is(err, &database.NoRowFoundError{}) {
return zerrors.ThrowNotFound(err, "DOM-rbdCv3", "session not found")
return ErrSessionNotFound(err, u.SessionID) // TODO: not found vs precondition failed
}
return zerrors.ThrowInternal(err, "DOM-To1rLz", "failed fetching session")
return ErrInternal(err, "failed to fetch the session")
}
if session.UserID != "" && u.FetchedUser.ID != "" && session.UserID != u.FetchedUser.ID {
return zerrors.ThrowInvalidArgument(nil, "DOM-78g1TV", "user change not possible")
return ErrSessionUserChange()
}
userFactor := &SessionFactorUser{
UserID: u.FetchedUser.ID,
@@ -97,16 +97,14 @@ func (u *UserCheckCommand) Execute(ctx context.Context, opts *InvokeOpts) (err e
updateCount, err := sessionRepo.Update(ctx, opts.DB(), sessionRepo.IDCondition(session.ID), sessionRepo.SetFactor(userFactor))
if err != nil {
return zerrors.ThrowInternal(err, "DOM-netNam", "failed updating session")
return ErrInternal(err, "failed to update the session")
}
if updateCount == 0 {
err = zerrors.ThrowNotFound(nil, "DOM-FszyWS", "session not found")
return err
return ErrSessionNotFound(err, u.SessionID) // TODO: not found vs precondition failed vs internal
}
if updateCount > 1 {
err = zerrors.ThrowInternal(NewMultipleObjectsUpdatedError(1, updateCount), "DOM-SsIwDt", "unexpected number of rows updated")
return err
return ErrMoreThanOneRowAffected("unexpected number of rows updated", updateCount)
}
u.UserCheckedAt = userFactor.LastVerifiedAt
@@ -126,37 +124,41 @@ func (u *UserCheckCommand) Validate(ctx context.Context, opts *InvokeOpts) (err
}
if u.SessionID == "" {
return zerrors.ThrowPreconditionFailed(nil, "DOM-00o0ys", "Errors.Missing.SessionID")
return ErrIDMissing() // TODO: precondition failed vs invalid argument
}
if u.InstanceID == "" {
return zerrors.ThrowPreconditionFailed(nil, "DOM-Oe1dtz", "Errors.Missing.InstanceID")
return ErrInstanceIDMissing() // TODO: precondition failed vs invalid argument
}
if authZErr := opts.Permissions.CheckSessionPermission(ctx, SessionWritePermission, u.SessionID); authZErr != nil {
// TODO: return a more specific error once permissions are implemented?
return zerrors.ThrowPermissionDenied(authZErr, "DOM-4qz3mt", "Errors.PermissionDenied")
}
var usrQueryOpt database.QueryOption
var query string
userRepo := opts.userRepo
if loginName := u.InputCheckUser.LoginName; loginName != "" {
usrQueryOpt = database.WithCondition(userRepo.LoginNameCondition(database.TextOperationEqual, loginName))
query = loginName
} else if userID := u.InputCheckUser.UserID; userID != "" {
usrQueryOpt = database.WithCondition(userRepo.IDCondition(userID))
query = userID
} else {
return zerrors.ThrowInvalidArgument(nil, "DOM-7B2m0b", "no valid query option")
return ErrInvalidRequest("either login_name or user_id is required")
}
usr, err := userRepo.Get(ctx, opts.DB(), usrQueryOpt)
if err != nil {
if errors.Is(err, &database.NoRowFoundError{}) {
return zerrors.ThrowNotFound(err, "DOM-lcZeXI", "user not found")
return ErrUserNotFound(err, query)
}
return zerrors.ThrowInternal(err, "DOM-Y846I0", "failed fetching user")
return ErrInternal(err, "failed to fetch the user")
}
if usr.State != UserStateActive {
return zerrors.ThrowPreconditionFailed(nil, "DOM-vgDIu9", "Errors.User.NotActive")
return ErrUserNotActive(usr.ID, "user must be active for sign in")
}
u.FetchedUser = *usr