Tencent/WeKnora · warning

invalid favorite resource type

Error message

invalid favorite resource type

What it means

ErrFavoriteInvalidType is a sentinel error returned by the user resource favorite service when a resourceType argument is not one of the recognized favorite resource types. The service validates via types.IsValidFavoriteResourceType before touching the repository, so callers get a clean domain error instead of GORM internals. It applies to List, Add, Remove and their handler-facing wrappers.

Source

Thrown at internal/application/service/user_resource_favorite.go:15

package service

import (
	"context"
	"errors"
	"strings"

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

// Sentinel errors so the handler can map cleanly to HTTP status codes
// without leaking GORM internals.
var (
	ErrFavoriteInvalidType = errors.New("invalid favorite resource type")
	ErrFavoriteEmptyID     = errors.New("favorite resource id is required")
)

type userResourceFavoriteService struct {
	repo interfaces.UserResourceFavoriteRepository
}

// NewUserResourceFavoriteService wraps the repository with input
// validation (allowlist of resource types, non-empty resource id).
// We keep service thin on purpose — favoriting is a non-business action
// that doesn't need audit logging or cross-aggregate side effects.
func NewUserResourceFavoriteService(repo interfaces.UserResourceFavoriteRepository) interfaces.UserResourceFavoriteService {
	return &userResourceFavoriteService{repo: repo}
}

func (s *userResourceFavoriteService) List(
	ctx context.Context, userID string, tenantID uint64, resourceType string,
) ([]*types.UserResourceFavorite, error) {

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Check the accepted values in types.IsValidFavoriteResourceType and send one of those exact strings.
  2. Normalize the resource type (trim/lowercase) at the handler boundary before calling the service.
  3. If a new resource type should be favoritable, add it to the validator's allowed set.

Example fix

// before
svc.AddFavorite(ctx, userID, tenantID, "Documents", resourceID)
// after (use an allowed type constant)
svc.AddFavorite(ctx, userID, tenantID, types.FavoriteResourceTypeDocument, resourceID)
Defensive patterns

Strategy: validation

Validate before calling

if !types.IsValidFavoriteResourceType(resourceType) {
    return httpError(400, fmt.Sprintf("unsupported resource type %q", resourceType))
}

Try / catch

// handler
if errors.Is(err, service.ErrFavoriteInvalidType) {
    return httpError(400, err.Error())
}

Prevention

When it happens

Trigger: Calling ListFavorites/AddFavorite/RemoveFavorite (or the service methods List/Add/Remove) with a resourceType string not accepted by types.IsValidFavoriteResourceType — e.g. a typo, different casing, or a new type the validator does not know.

Common situations: Client sends an arbitrary resource type in a request path/body; frontend and backend type enums drift after adding a new favoritable resource; case-sensitive mismatch like "Document" vs "document".

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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