juicedata/juicefs · error

negative duration for %s: %s

Error message

negative duration for %s: %s

What it means

Returned by `juicefs config` when a duration flag (changelog-max-age) is given a negative value. Durations for retention windows cannot be negative, so the update is rejected before the format is modified.

Source

Thrown at cmd/config.go:324

			}
		case "dir-stats":
			if new := ctx.Bool(flag); new != format.DirStats {
				msg.WriteString(fmt.Sprintf("%10s: %t -> %t\n", flag, format.DirStats, new))
				format.DirStats = new
			}
		case "changelog":
			if new := ctx.Bool(flag); new != format.ChangeLog {
				msg.WriteString(fmt.Sprintf("%10s: %t -> %t\n", flag, format.ChangeLog, new))
				format.ChangeLog = new
				if new && format.ChangeLogMaxAge == 0 && !ctx.IsSet("changelog-max-age") {
					format.ChangeLogMaxAge = 7200
					msg.WriteString(fmt.Sprintf("%10s: 0s -> %s (default)\n", "changelog-max-age", time.Duration(7200)*time.Second))
				}
			}
		case "changelog-max-age":
			d := ctx.Duration(flag)
			if d < 0 {
				return fmt.Errorf("negative duration for %s: %s", flag, d)
			}
			newAge := int64(d.Seconds())
			if newAge != format.ChangeLogMaxAge {
				msg.WriteString(fmt.Sprintf("%10s: %s -> %s\n", flag, time.Duration(format.ChangeLogMaxAge)*time.Second, d))
				format.ChangeLogMaxAge = newAge
			}
		case "changelog-max-lines":
			if new := ctx.Int64(flag); new != format.ChangeLogMaxLines {
				if new < 0 {
					return fmt.Errorf("negative value for %s: %d", flag, new)
				}
				msg.WriteString(fmt.Sprintf("%10s: %d -> %d\n", flag, format.ChangeLogMaxLines, new))
				format.ChangeLogMaxLines = new
			}
		case "user-group-quota":
			if new := ctx.Bool(flag); new != format.UserGroupQuota {
				msg.WriteString(fmt.Sprintf("%10s: %t -> %t\n", flag, format.UserGroupQuota, new))
				format.UserGroupQuota = new

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Pass a non-negative duration, e.g. `--changelog-max-age 2h`
  2. Fix the computation producing the negative duration
  3. Use 0 to fall back to the default (7200s)

Example fix

// before
juicefs config sqlite3://test.db --changelog-max-age -1h
// after
juicefs config sqlite3://test.db --changelog-max-age 1h
Defensive patterns

Strategy: validation

Validate before calling

case "$AGE" in -*) die "changelog-max-age must be non-negative";; esac

Prevention

When it happens

Trigger: `juicefs config META --changelog-max-age -30m` or any negative Go duration string passed to the flag.

Common situations: Script computing durations from signed arithmetic; misunderstanding that 0 disables retention (0 means default/unset per surrounding code).

Understand the failure class

Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.

Related errors


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