zitadel/zitadel · error

%s %s: %w

Error message

%s %s: %w

What it means

The InitPushFunc migration (40) executes its SQL statements and wraps failures as fmt.Errorf("%s %s: %w", mig.String(), stmt.file, err) — "<migration> <file>: <cause>". It then closes idle pool connections because old prepared statements would otherwise replay with wrong types; the wrapper pinpoints which SQL file of migration 40 failed.

Source

Thrown at cmd/setup/40.go:52

func (mig *InitPushFunc) Execute(ctx context.Context, _ eventstore.Event) (err error) {
	conn, err := mig.dbClient.Conn(ctx)
	if err != nil {
		return err
	}
	defer func() {
		closeErr := conn.Close()
		logging.OnError(ctx, closeErr).Debug("failed to release connection")
		// Force the pool to reopen connections to apply the new types
		mig.dbClient.Pool.Reset()
	}()
	statements, err := mig.prepareStatements(ctx)
	if err != nil {
		return err
	}
	for _, stmt := range statements {
		logging.Info(ctx, "execute statement", "file", stmt.file, "migration", mig.String())
		if _, err := conn.ExecContext(ctx, stmt.query); err != nil {
			return fmt.Errorf("%s %s: %w", mig.String(), stmt.file, err)
		}
	}
	// close idle connections to prevent them from using the old prepared statement with the wrong type
	// and having wrong plan of `eventstore.command2`-type
	for _, conn := range mig.dbClient.Pool.AcquireAllIdle(ctx) {
		logging.OnError(ctx, conn.Conn().Close(ctx)).Debug("failed to close idle connection")
		conn.Release()
	}

	return nil
}

func (mig *InitPushFunc) String() string {
	return "40_init_push_func_v4"
}

func (mig *InitPushFunc) prepareStatements(ctx context.Context) ([]statement, error) {
	funcTmpl, err := template.ParseFS(initPushFunc, mig.filePath(fileFunc))

View on GitHub (pinned to 13948f2bcd)

Solutions

  1. Check the named SQL file and the wrapped pg error; run the statement manually to see the exact failure.
  2. Ensure the DB user can create/replace functions and types in the eventstore schema.
  3. Confirm the source ZITADEL version is one that migration 40 supports upgrading from.
Defensive patterns

Strategy: retry

Validate before calling

// check privileges to create functions
SELECT has_schema_privilege(current_user, 'eventstore', 'CREATE');

Try / catch

if _, err := conn.ExecContext(ctx, stmt.query); err != nil {
    var pgErr *pgconn.PgError
    if errors.As(err, &pgErr) { /* handle by pgErr.Code */ }
    return fmt.Errorf("%s %s: %w", mig.String(), stmt.file, err)
}

Prevention

When it happens

Trigger: ExecContext failure on any statement of 40_init_push_func_v4: SQL syntax/type errors, missing eventstore.command2 type, or insufficient privileges to create functions.

Common situations: Upgrading from a ZITADEL version whose push function/aggregate type differs; DB user lacking CREATE FUNCTION privilege; prepared-statement type conflicts from pooled connections.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of zitadel/zitadel@13948f2bcd (2026-09-06). Data as JSON: /api/errors/4d72f986db6535ab. Report an issue: GitHub.