siyuan-note/siyuan · error
rating must be an integer from 0 to 5
Error message
rating must be an integer from 0 to 5
What it means
Range validation at the top of SetBazaarPackageRating: fires when userRating is outside 0..5 (or the cancellation path mishandles it), before any cloud request is made. Ratings are integers 0–5 where cancellation uses a sentinel; an out-of-range value is the faulting input, unlike the separate error for invalid ratings returned by the cloud server.
Solutions
- Pass 0 to cancel a rating, 1-5 to set one; clamp/validate input before calling
- Map the UI star value with 0 as the 'none' sentinel
- Check bounds (0 <= r <= 5) at the API boundary
Example fix
// before model.SetBazaarPackageRating(ctx, "plugins", name, -1) // cancel attempt // after model.SetBazaarPackageRating(ctx, "plugins", name, 0) // 0 cancels the rating
Defensive patterns
Strategy: validation
Validate before calling
if userRating < 0 || userRating > 5 {
return errors.New("rating must be an integer from 0 to 5")
} Prevention
- Use 0 as the single 'cancel rating' sentinel everywhere
- Clamp star-widget values to 1..5 and map 'none' to 0
- Validate user input at the UI boundary before invoking the kernel
When it happens
Trigger: Calling SetBazaarPackageRating with userRating < 0 or > 5, e.g. -1 for 'unset' or a 1..5 star value shifted off by one.
Common situations: UI code using 1-5 stars and passing 5 as 'no rating' instead of 0; off-by-one in star widget mapping; passing an unbounded parsed integer from user input.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- attribute view custom color index
- document IDs are required
- invalid attribute view source
- invalid package type
- invalid paste row count
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/4a950b566c430771.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/bazaar_rating.go:154
"token": token,
"packageName": packageName,
}, &data)
if nil != err {
return nil, false, 0, err
}
if 0 > data.Rating || 5 < data.Rating {
return nil, false, 0, errors.New("invalid user rating returned by cloud server")
}
rating, ratingAvailable = bazaar.GetBazaarPackageRating(ctx, packageName)
return rating, ratingAvailable, data.Rating, nil
}
// SetBazaarPackageRating 设置或取消已安装官方包的当前用户评分。
func SetBazaarPackageRating(ctx context.Context, pkgType, packageName string, userRating int) (rating *bazaar.PackageRating,
ratingAvailable bool, retUserRating int, err error) {
if 0 > userRating || 5 < userRating {
return nil, false, 0, errors.New("rating must be an integer from 0 to 5")
}
bazaarRatingSetMu.Lock()
defer bazaarRatingSetMu.Unlock()
token, err := bazaarRatingValidatePackage(ctx, pkgType, packageName)
if nil != err {
return nil, false, 0, err
}
region := util.CurrentCloudRegion
data := bazaarPackageSetRatingData{}
err = requestBazaarPackageRating(ctx, "/apis/siyuan/bazaar/setBazaarPackageRating", map[string]any{
"token": token,
"packageName": packageName,
"rating": userRating,
}, &data)
if nil != err {
return nil, false, 0, errView on GitHub (pinned to 9f775e8a12)