Tencent/WeKnora · error

repository: pending invitation already exists

Error message

repository: pending invitation already exists

What it means

Sentinel ErrPendingInvitationExists returned by invitation repository Create when inserting hits a unique-conflict on (tenant_id, invitee_user_id) because an already-pending invitation exists. The service layer re-maps it to its own sentinel and the handler responds 409 Conflict.

Source

Thrown at internal/application/repository/tenant_invitation.go:16

package repository

import (
	"context"
	"errors"
	"time"

	"github.com/Tencent/WeKnora/internal/types"
	"github.com/Tencent/WeKnora/internal/types/interfaces"
	"gorm.io/gorm"
)

// ErrPendingInvitationExists is returned by Create when a pending
// invitation for (tenant_id, invitee_user_id) already exists. The
// service layer maps it to its own sentinel for the handler.
var ErrPendingInvitationExists = errors.New("repository: pending invitation already exists")

// tenantInvitationRepository implements interfaces.TenantInvitationRepository.
type tenantInvitationRepository struct {
	db *gorm.DB
}

// NewTenantInvitationRepository constructs the repo against db. Wired
// up via the dig container alongside other repositories.
func NewTenantInvitationRepository(db *gorm.DB) interfaces.TenantInvitationRepository {
	return &tenantInvitationRepository{db: db}
}

// Create inserts a new pending invitation row. The partial unique
// index on (tenant_id, invitee_user_id) WHERE status='pending' is the
// authoritative guard against duplicates, but we ALSO pre-check via
// GetPendingByPair inside a tiny transaction so the typical "click
// twice fast" case returns a clean sentinel instead of a raw 23505 /
// SQLITE_CONSTRAINT error string the handler would have to parse.

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Do not create a duplicate; notify the user that an invitation is already pending
  2. If the old invitation should be replaced, revoke/cancel it first, then create the new one
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at internal/application/repository/tenant_invitation.go:16 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/0d1844bc08f55718. Report an issue: GitHub.