vxcontrol/pentagi · error
invalid UserStatus: %s
Error message
invalid UserStatus: %s
What it means
UserStatus.Valid() is a GORM model validation guard for the users table in backend/pkg/server/models/users.go:32. It only accepts the enum values UserStatusCreated, UserStatusActive, and UserStatusBlocked; any other string carried in a User's Status field is rejected with this formatted error. It runs via the Validate(db) callback whenever a User record is created or updated, so a bad status blocks persistence instead of writing corrupt data.
Source
Thrown at backend/pkg/server/models/users.go:32
type UserStatus string
const (
UserStatusCreated UserStatus = "created"
UserStatusActive UserStatus = "active"
UserStatusBlocked UserStatus = "blocked"
)
func (s UserStatus) String() string {
return string(s)
}
// Valid is function to control input/output data
func (s UserStatus) Valid() error {
switch s {
case UserStatusCreated, UserStatusActive, UserStatusBlocked:
return nil
default:
return fmt.Errorf("invalid UserStatus: %s", s)
}
}
// Validate is function to use callback to control input/output data
func (s UserStatus) Validate(db *gorm.DB) {
if err := s.Valid(); err != nil {
db.AddError(err)
}
}
type UserType string
const (
UserTypeLocal UserType = "local"
UserTypeOAuth UserType = "oauth"
UserTypeAPI UserType = "api"
)
View on GitHub (pinned to ea665308ba)
Solutions
- Set the user's Status to one of the exported constants (UserStatusCreated, UserStatusActive, UserStatusBlocked) before saving.
- If the value comes from external input, map/normalize it to a known constant and reject unknown values at the API boundary.
- If a new status is genuinely required, add a UserStatus* constant and extend the switch in Valid() rather than passing a raw string.
Example fix
// before
user := models.User{Name: "alice"} // Status empty
orm.Create(&user) // invalid UserStatus:
// after
user := models.User{Name: "alice", Status: models.UserStatusActive}
orm.Create(&user) Defensive patterns
Strategy: validation
Validate before calling
if err := models.UserStatus(status).Valid(); err != nil {
return fmt.Errorf("invalid status %q: %w", status, err)
} Type guard
func validUserStatus(s models.UserStatus) bool {
switch s {
case models.UserStatusCreated, models.UserStatusActive, models.UserStatusBlocked:
return true
}
return false
} Try / catch
if err := orm.Create(&user).Error; err != nil {
if strings.HasPrefix(err.Error(), "invalid UserStatus") {
return fmt.Errorf("bad status %q: %w", user.Status, err)
}
return err
} Prevention
- Only assign Status via the exported constants, never raw strings.
- Validate user-controlled status values at the API boundary before building the model.
- Add a unit test asserting every persisted status passes Valid().
When it happens
Trigger: Saving (Create/Save/Updates) or serializing a User whose Status field is an empty string, a hand-written string like "actve", or any value not exactly equal to one of the three accepted enum constants.
Common situations: Constructing a User struct in code or tests without initializing Status; inserting rows via raw SQL or an external service that writes status values not present in the Go enum set; refactoring or DB migration that renames status strings without updating the constants.
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
- invalid UserType: %s
- invalid VecstoreActionType: %s
- invalid UsageStatsPeriod: %s
- invalid TokenStatus: %s
- invalid AssistantStatus: %s
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/ad5906438fff148b.
Report an issue: GitHub.