hashicorp/nomad · error

hg_timeout not a valid duration: %w

Error message

hg_timeout not a valid duration: %w

What it means

Returned by ArtifactConfig.Validate when hg_timeout is set but time.ParseDuration cannot parse the string as a Go duration. Valid values look like "5m", "30s", "1h"; the wrapped error indicates the malformed portion.

Source

Thrown at nomad/structs/config/artifact.go:206

		return fmt.Errorf("gcs_timeout not a valid duration: %w", err)
	} else if v < 0 {
		return fmt.Errorf("gcs_timeout must be > 0")
	}

	if a.GitTimeout == nil {
		return fmt.Errorf("git_timeout must be set")
	}
	if v, err := time.ParseDuration(*a.GitTimeout); err != nil {
		return fmt.Errorf("git_timeout not a valid duration: %w", err)
	} else if v < 0 {
		return fmt.Errorf("git_timeout must be > 0")
	}

	if a.HgTimeout == nil {
		return fmt.Errorf("hg_timeout must be set")
	}
	if v, err := time.ParseDuration(*a.HgTimeout); err != nil {
		return fmt.Errorf("hg_timeout not a valid duration: %w", err)
	} else if v < 0 {
		return fmt.Errorf("hg_timeout must be > 0")
	}

	if a.S3Timeout == nil {
		return fmt.Errorf("s3_timeout must be set")
	}
	if v, err := time.ParseDuration(*a.S3Timeout); err != nil {
		return fmt.Errorf("s3_timeout not a valid duration: %w", err)
	} else if v < 0 {
		return fmt.Errorf("s3_timeout must be > 0")
	}

	if a.DecompressionFileCountLimit == nil {
		return fmt.Errorf("decompression_file_count_limit must not be nil")
	}
	if v := *a.DecompressionFileCountLimit; v < 0 {
		return fmt.Errorf("decompression_file_count_limit must be >= 0 but found %d", v)

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Use a valid Go duration string, e.g. `hg_timeout = "5m"` or "300s".
  2. Ensure templated values carry the unit suffix.
  3. Read the wrapped %w error to locate the exact invalid characters.
  4. Confirm with `nomad validate` before restarting the agent.

Example fix

// before
artifact {
  hg_timeout = "300"
}
// after
artifact {
  hg_timeout = "300s"
}
Defensive patterns

Strategy: validation

Validate before calling

func validHgTimeout(s *string) bool {
    if s == nil { return false }
    _, err := time.ParseDuration(*s)
    return err == nil
}

Type guard

func isDuration(s string) bool {
    _, err := time.ParseDuration(s)
    return err == nil
}

Prevention

When it happens

Trigger: Setting `hg_timeout` to "5" (unit missing), "5 minutes", "5min", "", or a numeric value injected by templating without a suffix.

Common situations: Assuming bare integers mean seconds; copying duration formats from non-Go tooling; env var substitution stripping units; typos like "5 m" with an internal space.

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 hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/cc7d5e4015e334e3. Report an issue: GitHub.