gohugoio/hugo · error

invalid value for flag poll

Error message

invalid value for flag poll: %s

What it means

`hugoBuilder.newWatcher` parses the `--poll` flag string with `types.ToDurationE` into a `time.Duration`. This error wraps the parse failure, meaning the supplied string is not a value Go's `time.ParseDuration` can interpret.

Solutions

  1. Supply a unit-suffixed duration, e.g. `--poll=250ms` or `--poll=2s`.
  2. Omit `--poll` to use the default fsnotify watcher (polling disabled).
  3. Check the exact flag value in your script/CI env for stray characters.

Example fix

// before
// $ hugo server --poll=500
// after
// $ hugo server --poll=500ms
Defensive patterns

Strategy: validation

Validate before calling

// Validate the --poll string the same way Hugo will.
import "time"
func validatePollFlag(s string) error {
  if s == "" { return nil }
  _, err := time.ParseDuration(s)
  return err
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Fires only when `pollIntervalStr != ""` and `types.ToDurationE` errors — e.g. `--poll=500`, `--poll=fast`, or any value missing a unit or using an unsupported suffix.

Common situations: Passing a bare number like `--poll=250` (Go durations require a unit such as `ms`, `s`); using `--poll=250ms` works while `--poll=0.25s` works too; typos like `--poll=250msec`.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/8023c10c94b8ffec. Report an issue: GitHub.

Appendix: source

Thrown at commands/hugobuilder.go:322

		return nil, fmt.Errorf("failed to start trace: %w", err)
	}

	return func() {
		trace.Stop()
		f.Close()
	}, nil
}

// newWatcher creates a new watcher to watch filesystem events.
func (c *hugoBuilder) newWatcher(pollIntervalStr string, dirList ...string) (*watcher.Batcher, error) {
	staticSyncer := &staticSyncer{c: c}

	var pollInterval time.Duration
	poll := pollIntervalStr != ""
	if poll {
		pollInterval, err := types.ToDurationE(pollIntervalStr)
		if err != nil {
			return nil, fmt.Errorf("invalid value for flag poll: %s", err)
		}
		c.r.logger.Printf("Use watcher with poll interval %v", pollInterval)
	}

	if pollInterval == 0 {
		pollInterval = 500 * time.Millisecond
	}

	watcher, err := watcher.New(500*time.Millisecond, pollInterval, poll)
	if err != nil {
		return nil, err
	}

	h, err := c.hugo()
	if err != nil {
		return nil, err
	}
	spec := h.Deps.SourceSpec

View on GitHub (pinned to 52c9bd7908)