Tencent/WeKnora · error
tenant not found
Error message
tenant not found
What it means
Sentinel ErrTenantNotFound returned by tenant repository getters when GORM reports gorm.ErrRecordNotFound for the given tenant id — the id was valid syntactically but no tenant row exists (deleted or never created). It is a mapped not-found, not a DB error.
Source
Thrown at internal/application/repository/tenant.go:15
package repository
import (
"context"
"errors"
"github.com/Tencent/WeKnora/internal/logger"
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/types/interfaces"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
var (
ErrTenantNotFound = errors.New("tenant not found")
ErrTenantHasKnowledgeBase = errors.New("tenant has associated knowledge bases")
)
// tenantRepository implements tenant repository interface
type tenantRepository struct {
db *gorm.DB
}
// NewTenantRepository creates a new tenant repository
func NewTenantRepository(db *gorm.DB) interfaces.TenantRepository {
return &tenantRepository{db: db}
}
// CreateTenant creates tenant
func (r *tenantRepository) CreateTenant(ctx context.Context, tenant *types.Tenant) error {
return r.db.WithContext(ctx).Create(tenant).Error
}
View on GitHub (pinned to 988cbb0330)
Solutions
- Verify the tenant id in the request/auth context is correct and still exists
- Create the tenant first, or return 404 to the caller instead of retrying
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at internal/application/repository/tenant.go:15 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/97b43d6e88f17569.
Report an issue: GitHub.