juicedata/juicefs · error
invalid quota type: %d
Error message
invalid quota type: %d
What it means
kvMeta.getQuotaKey maps a quota type constant (DirQuotaType, UserQuotaType, GroupQuotaType) to its key builder; an unknown qtype has no key representation, so it returns this error instead of building a key. It is an API-misuse guard inside the quota subsystem.
Source
Thrown at pkg/meta/tkv.go:3486
if value == nil {
return ENOATTR
}
tx.delete(key)
m.genLog(tx, time.Now(), "REMOVEXATTR(%d,%s)", inode, logEncode2(name))
return nil
}, inode))
}
func (m *kvMeta) getQuotaKey(qtype uint32, key uint64) ([]byte, error) {
switch qtype {
case DirQuotaType:
return m.dirQuotaKey(Ino(key)), nil
case UserQuotaType:
return m.userQuotaKey(key), nil
case GroupQuotaType:
return m.groupQuotaKey(key), nil
default:
return nil, fmt.Errorf("invalid quota type: %d", qtype)
}
}
func (m *kvMeta) doGetQuota(ctx Context, qtype uint32, key uint64) (*Quota, error) {
quotaKey, err := m.getQuotaKey(qtype, key)
if err != nil {
return nil, err
}
buf, err := m.get(quotaKey)
if err != nil {
return nil, err
}
if buf == nil {
return nil, nil
}
if len(buf) != 32 {
return nil, fmt.Errorf("invalid quota value: %v", buf)View on GitHub (pinned to c9a67b23e8)
Solutions
- Pass one of the exported quota type constants (DirQuotaType, UserQuotaType, GroupQuotaType) instead of a raw number
- Check for zero-value/uninitialized qtype variables before calling the quota API
- If you added a new quota type, extend getQuotaKey to handle it
- Log the qtype at the call site to confirm which invalid value is being passed
Example fix
// before m.doGetQuota(ctx, 2, ino) // after m.doGetQuota(ctx, DirQuotaType, uint64(ino))
Defensive patterns
Strategy: validation
Validate before calling
const (
DirQuotaType uint32 = iota
UserQuotaType
GroupQuotaType
)
if qtype > GroupQuotaType {
return fmt.Errorf("qtype %d out of range", qtype)
} Try / catch
if err := m.doGetQuota(ctx, qtype, key); err != nil {
if strings.Contains(err.Error(), "invalid quota type") {
// fix the qtype constant at the call site
}
} Prevention
- Always pass the exported quota type constants, never raw integers
- Guard against Go zero-value uint32 (0 is valid only for DirQuotaType; uninitialized vars may be unintended)
- Extend getQuotaKey first if introducing a new quota type
- Add a switch/default assertion at the call site
When it happens
Trigger: Calling doGetQuota/doSetQuota/doDeleteQuota (or higher-level quota APIs) with a qtype value other than the defined DirQuotaType/UserQuotaType/GroupQuotaType constants.
Common situations: Plugin or downstream code passing a raw integer for quota type; constants renamed/added in newer JuiceFS versions and passed across module boundaries; copy-paste of an uninitialized qtype variable.
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
- no quota for inode %d path %s
- quota of %s is inconsistent, please repair it with --repair
- clean %s quotas: %w
- set %s quota: %w
- scan global user group usage: %w
AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06).
Data as JSON: /api/errors/cf56ecf624ae2d22.
Report an issue: GitHub.