siyuan-note/siyuan · error

invalid package type

Error message

invalid package type

What it means

Error returned at the top of model.GetInstalledBazaarPackageRatings (kernel/model/bazaar_rating.go:66) when isValidBazaarPackageType rejects pkgType. The rating subsystem accepts exactly plugins, widgets, icons, templates, themes (same set as the install enumeration in bazaar.go); anything else fails fast before any installed-info enumeration or cloud call. The same message also exists in validateBazaarPackageRatingRequest0 for the single-package endpoints.

Source

Thrown at kernel/model/bazaar_rating.go:66

type bazaarPackageUserRatingData struct {
	Rating int `json:"rating"`
}

type bazaarPackageSetRatingData struct {
	Rating          int                   `json:"rating"`
	RatingAvailable *bool                 `json:"ratingAvailable"`
	PublicRating    *bazaar.PackageRating `json:"publicRating"`
	Distribution    []int64               `json:"distribution"`
}

// ErrBazaarRatingRateLimited 表示评分请求受到云端频率限制。
var ErrBazaarRatingRateLimited = errors.New("bazaar rating rate limited")

// GetInstalledBazaarPackageRatings 获取指定已安装包的公开评分。
func GetInstalledBazaarPackageRatings(ctx context.Context, pkgType string,
	packageNames []string) (ratings map[string]*bazaar.PackageRating, eligiblePackageNames []string, err error) {
	if !isValidBazaarPackageType(pkgType) {
		return nil, nil, errors.New("invalid package type")
	}

	installedInfos, _, _, err := bazaarRatingInstalledPackageInfos(pkgType)
	if nil != err {
		return nil, nil, err
	}
	installed := make(map[string]bool, len(installedInfos))
	for _, info := range installedInfos {
		if "" == info.Pkg.InvalidReason {
			installed[info.Pkg.Name] = true
		}
	}

	names := make([]string, 0, len(packageNames))
	seen := make(map[string]bool, len(packageNames))
	for _, packageName := range packageNames {
		if !bazaar.IsValidPackageName(packageName) {
			return nil, nil, fmt.Errorf("invalid package name: %s", packageName)

View on GitHub (pinned to afa823b6b4)

Solutions

  1. Send one of: plugins, widgets, icons, templates, themes (lowercase, plural)
  2. Validate pkgType at the client boundary with the same five-value whitelist before calling the API
  3. Return a 400 with the allowed list instead of forwarding the raw value when building a proxy/frontend
Defensive patterns

Strategy: validation

Validate before calling

switch pkgType {
case "plugins", "widgets", "icons", "templates", "themes":
    // ok
default:
    return fmt.Errorf("invalid package type %q", pkgType)
}

Prevention

When it happens

Trigger: Calling /api/bazaar/getInstalledBazaarPackageRatings or the per-package rating endpoints with pkgType="plugin" (singular), an empty string, or a custom type string invented by the client.

Common situations: Client reuses an internal type constant that doesn't match the bazaar vocabulary; copy-paste from another API that uses different type names; unvalidated query parameters forwarded straight to the kernel.

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 siyuan-note/siyuan@afa823b6b4 (2026-08-18). Data as JSON: /api/errors/7097d68388736e93. Report an issue: GitHub.