benbjohnson/litestream · error
snapshot interval must be greater than 0
Error message
snapshot interval must be greater than 0
What it means
Sentinel error ErrInvalidSnapshotInterval is returned by Config.Validate when a configured snapshot interval is present but less than or equal to zero. Snapshot interval controls how often litestream takes full snapshots, so a non-positive value is meaningless and rejected at config validation time. The error is wrapped in a ConfigValidationError that names the offending field (snapshot.interval or dbs[<id>].snapshot.interval) and its value.
Source
Thrown at cmd/litestream/main.go:53
"github.com/benbjohnson/litestream/sftp"
"github.com/benbjohnson/litestream/webdav"
)
// Version is set via -ldflags "-X main.Version=..." on release and Makefile
// builds; otherwise it is resolved from embedded VCS build info at startup.
var Version = defaultVersion
func init() {
bi, _ := debug.ReadBuildInfo()
Version = resolveVersion(Version, bi)
}
// errStop is a terminal error for indicating program should quit.
var errStop = errors.New("stop")
// Sentinel errors for configuration validation
var (
ErrInvalidSnapshotInterval = errors.New("snapshot interval must be greater than 0")
ErrInvalidSnapshotRetention = errors.New("snapshot retention must be greater than 0")
ErrInvalidCompactionInterval = errors.New("compaction interval must be greater than 0")
ErrInvalidSyncInterval = errors.New("sync interval must be greater than 0")
ErrInvalidL0Retention = errors.New("l0 retention must not be negative")
ErrInvalidL0RetentionCheckInterval = errors.New("l0 retention check interval must be greater than 0")
ErrInvalidShutdownSyncTimeout = errors.New("shutdown-sync-timeout must be >= 0")
ErrInvalidShutdownSyncInterval = errors.New("shutdown sync interval must be greater than 0")
ErrInvalidHeartbeatURL = errors.New("heartbeat URL must be a valid HTTP or HTTPS URL")
ErrInvalidHeartbeatInterval = errors.New("heartbeat interval must be at least 1 minute")
ErrConfigFileNotFound = errors.New("config file not found")
)
// ConfigValidationError wraps a validation error with additional context
type ConfigValidationError struct {
Err error
Field string
Value interface{}
}View on GitHub (pinned to 4ed7a308f6)
Solutions
- Set snapshot.interval to a positive duration (e.g. "24h") in the config file, or remove the key to use the default.
- If the value comes from a template/variable, ensure it expands to a valid positive duration.
- Run litestream with the corrected config and re-check with `litestream -config <file> ...` validation output for the reported field.
Example fix
# before snapshot: interval: 0 # after snapshot: interval: 24h
Defensive patterns
Strategy: validation
Validate before calling
func validSnapshotInterval(d time.Duration) bool { return d > 0 }
// call before writing/loading config:
if !validSnapshotInterval(cfg.Snapshot.IntervalDur) { return errors.New("snapshot.interval must be > 0") } Try / catch
if err := cfg.Validate(); err != nil {
var ve *main.ConfigValidationError
if errors.As(err, &ve) && errors.Is(ve.Err, main.ErrInvalidSnapshotInterval) {
log.Fatalf("bad snapshot interval at %s = %v", ve.Field, ve.Value)
}
return err
} Prevention
- Always write durations with explicit units ("24h") in litestream config files.
- Validate the config with cfg.Validate() at load time, before starting services.
- In templated configs, assert variables are non-empty before rendering intervals.
When it happens
Trigger: Setting snapshot.interval <= 0 in the top-level config, or snapshot.interval <= 0 under a dbs[] entry; calling Validate on a Config loaded from a TOML/YAML file containing such a value.
Common situations: Typo like interval = 0 intending 'use default'; a templated config where a variable expanded to 0 or an empty value coerced to 0; programmatically generating config with an unset duration defaulting to zero.
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
- snapshot retention must be greater than 0
- compaction interval must be greater than 0
- sync interval must be greater than 0
- l0 retention must not be negative
- l0 retention check interval must be greater than 0
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/380630ca5ce740ba.
Report an issue: GitHub.