hashicorp/nomad · error

error parsing HgTimeout: %w

Error message

error parsing HgTimeout: %w

What it means

ArtifactConfigFromAgent parses HgTimeout (Mercurial artifact fetch timeout) with time.ParseDuration. If the string is not a valid Go duration, the wrapped error is returned under this message and config construction fails.

Source

Thrown at client/config/artifact.go:60

	httpMaxSize, err := humanize.ParseBytes(*c.HTTPMaxSize)
	if err != nil {
		return nil, fmt.Errorf("error parsing HTTPMaxSize: %w", err)
	}

	gcsTimeout, err := time.ParseDuration(*c.GCSTimeout)
	if err != nil {
		return nil, fmt.Errorf("error parsing GCSTimeout: %w", err)
	}

	gitTimeout, err := time.ParseDuration(*c.GitTimeout)
	if err != nil {
		return nil, fmt.Errorf("error parsing GitTimeout: %w", err)
	}

	hgTimeout, err := time.ParseDuration(*c.HgTimeout)
	if err != nil {
		return nil, fmt.Errorf("error parsing HgTimeout: %w", err)
	}

	s3Timeout, err := time.ParseDuration(*c.S3Timeout)
	if err != nil {
		return nil, fmt.Errorf("error parsing S3Timeout: %w", err)
	}

	decompressionSizeLimit, err := humanize.ParseBytes(*c.DecompressionSizeLimit)
	if err != nil {
		return nil, fmt.Errorf("error parsing DecompressionLimitSize: %w", err)
	}

	return &ArtifactConfig{
		HTTPReadTimeout:               httpReadTimeout,
		HTTPMaxBytes:                  int64(httpMaxSize),
		GCSTimeout:                    gcsTimeout,
		GitTimeout:                    gitTimeout,
		HgTimeout:                     hgTimeout,

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Use a valid duration string for hg_timeout, e.g. "5m" or "300s"
  2. Check for empty values in the rendered agent config and set a default explicitly
  3. Pre-validate the raw string with time.ParseDuration before invoking ArtifactConfigFromAgent

Example fix

// before
hg_timeout = "60min"
// after
hg_timeout = "60m"
Defensive patterns

Strategy: validation

Validate before calling

if _, err := time.ParseDuration(*c.HgTimeout); err != nil {
    return fmt.Errorf("invalid hg_timeout %q: %w", *c.HgTimeout, err)
}

Type guard

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

Try / catch

cfg, err := config.ArtifactConfigFromAgent(agentCfg)
if err != nil {
    if strings.Contains(err.Error(), "error parsing HgTimeout") {
        return fmt.Errorf("hg_timeout must be a Go duration like 5m: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ArtifactConfigFromAgent with an ArtifactConfig whose HgTimeout string lacks a unit ("60"), uses an unsupported unit ("60min", "1hr"), or is empty.

Common situations: hg_timeout in the Nomad client artifact block miswritten; environments where Mercurial settings were added by hand or via automation that emitted bare integers; stale configs after upgrading Nomad which tightened parsing.

Understand the failure class

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/3d5c3989851f790d. Report an issue: GitHub.