juicedata/juicefs · error

invalid hour number

Error message

invalid hour number

What it means

parseHours validates the hour portion of cache-scan time ranges used by the disk cache free-space scan. It returns this error when either the start or end hour parsed from the range string is not a number between 0 and 23. The library throws it to reject malformed hour values in config options like free-space scan windows before they cause wrong scan scheduling.

Source

Thrown at pkg/chunk/cached_store.go:645

		return
	}
	split := ","
	if strings.Contains(c.UploadHours, "-") {
		split = "-"
	}
	ps := strings.Split(c.UploadHours, split)
	if len(ps) != 2 {
		err = errors.New("unexpected number of fields")
		return
	}
	if start, err = strconv.Atoi(ps[0]); err != nil {
		return
	}
	if end, err = strconv.Atoi(ps[1]); err != nil {
		return
	}
	if start < 0 || start > 23 || end < 0 || end > 23 {
		err = errors.New("invalid hour number")
	}
	return
}

func (c *Config) CacheEnabled() bool {
	return c.CacheSize > 0
}

type cachedStore struct {
	storage         object.ObjectStorage
	bcache          CacheManager
	fetcher         *prefetcher
	conf            Config
	group           *Controller
	currentUpload   chan struct{}
	currentDownload chan struct{}
	pendingCh       chan *pendingItem
	pendingKeys     map[string]*pendingItem

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Fix the hour range in the client config so both start and end are integers 0-23 (e.g. "0:6" instead of "0:24").
  2. If a full-day range is needed, use "0:23" or omit the range option so the scan runs unconditionally.
  3. Re-run juicefs mount after correcting the configuration and check the client log to confirm the cache scan starts.

Example fix

// before
--scan-hours 0:24
// after
--scan-hours 0:23
Defensive patterns

Strategy: validation

Validate before calling

func validHours(s string) bool {
	parts := strings.SplitN(s, ":", 2)
	if len(parts) != 2 { return false }
	a, err1 := strconv.Atoi(parts[0]); b, err2 := strconv.Atoi(parts[1])
	return err1 == nil && err2 == nil && a >= 0 && a <= 23 && b >= 0 && b <= 23
}

Prevention

When it happens

Trigger: Calling NewCachedStore or SelfCheck with a config whose scan-range / hour field contains hours outside 0-23 (e.g. "25:3" or "-1:8") after strconv.Atoi succeeded on both parts.

Common situations: Typo in a cache configuration time range, copy-pasting a 24-hour convention like "0:24", or using locale-formatted hours in the Juicedata cache config (e.g. --free-space-rand or scan hours settings).

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/f54814cba86c3875. Report an issue: GitHub.