fix(handler): updated failed events (#7146)

This commit is contained in:
Silvan 2024-01-04 22:36:08 +01:00 committed by GitHub
parent b7d027e2fd
commit aa2d642e97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -331,7 +331,7 @@ func (h *Handler) processEvents(ctx context.Context, config *triggerConfig) (add
return false, err
}
defer func() {
if err != nil {
if err != nil && !errors.Is(err, &executionError{}) {
rollbackErr := tx.Rollback()
h.log().OnError(rollbackErr).Debug("unable to rollback tx")
return
@ -472,7 +472,7 @@ func (h *Handler) executeStatement(ctx context.Context, tx *sql.Tx, currentState
return nil
}
return err
return &executionError{parent: err}
}
return nil

View File

@ -4,6 +4,7 @@ import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
"time"
@ -15,6 +16,26 @@ import (
"github.com/zitadel/zitadel/internal/zerrors"
)
var _ error = (*executionError)(nil)
type executionError struct {
parent error
}
// Error implements error.
func (s *executionError) Error() string {
return fmt.Sprintf("statement failed: %v", s.parent)
}
func (s *executionError) Is(err error) bool {
_, ok := err.(*executionError)
return ok
}
func (s *executionError) Unwrap() error {
return s.parent
}
func (h *Handler) eventsToStatements(tx *sql.Tx, events []eventstore.Event, currentState *state) (statements []*Statement, err error) {
statements = make([]*Statement, 0, len(events))