{"id":"8023c10c94b8ffec","repo":"gohugoio/hugo","slug":"invalid-value-for-flag-poll-s","errorCode":null,"errorMessage":"invalid value for flag poll: %s","messagePattern":"invalid value for flag poll: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/hugobuilder.go","lineNumber":322,"sourceCode":"\t\treturn nil, fmt.Errorf(\"failed to start trace: %w\", err)\n\t}\n\n\treturn func() {\n\t\ttrace.Stop()\n\t\tf.Close()\n\t}, nil\n}\n\n// newWatcher creates a new watcher to watch filesystem events.\nfunc (c *hugoBuilder) newWatcher(pollIntervalStr string, dirList ...string) (*watcher.Batcher, error) {\n\tstaticSyncer := &staticSyncer{c: c}\n\n\tvar pollInterval time.Duration\n\tpoll := pollIntervalStr != \"\"\n\tif poll {\n\t\tpollInterval, err := types.ToDurationE(pollIntervalStr)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid value for flag poll: %s\", err)\n\t\t}\n\t\tc.r.logger.Printf(\"Use watcher with poll interval %v\", pollInterval)\n\t}\n\n\tif pollInterval == 0 {\n\t\tpollInterval = 500 * time.Millisecond\n\t}\n\n\twatcher, err := watcher.New(500*time.Millisecond, pollInterval, poll)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\th, err := c.hugo()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tspec := h.Deps.SourceSpec","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/hugobuilder.go#L304-L340","documentation":"Returned by hugoBuilder.newWatcher when the --poll flag's value cannot be parsed into a time.Duration by types.ToDurationE. The --poll flag switches the file watcher to polling mode with the given interval, so an unparsable interval aborts watcher setup. The %s embeds the parse error rather than the raw flag value.","triggerScenarios":"Running `hugo server --poll <value>` (or hugo --watch --poll) with a value that isn't a valid duration string or number, e.g. --poll 5x, --poll fast, or malformed unit suffixes.","commonSituations":"Forgetting the unit (writing `--poll 700ms` works, but exotic or misspelled units like `5sec` don't), copying values from docs with typos, or shell quoting mishaps that mangle the value. Common on network/virtual filesystems (Docker on Windows/macOS, NFS) where polling is needed because inotify events don't propagate.","solutions":["Use a valid Go duration string, e.g. --poll 700ms or --poll 2s.","If you meant to just enable polling, still supply an interval (e.g. --poll 500ms, the default interval).","Check shell quoting so the value reaches Hugo intact."],"exampleFix":"# before\nhugo server --poll 5sec\n# after\nhugo server --poll 5s","handlingStrategy":"validation","validationCode":"// validate the poll interval before passing it as a flag\nif _, err := time.ParseDuration(pollValue); err != nil {\n    return fmt.Errorf(\"invalid --poll value %q: %w\", pollValue, err)\n}","typeGuard":"func isValidPoll(s string) bool {\n    _, err := time.ParseDuration(s)\n    return err == nil\n}","tryCatchPattern":"if err := cmd.Execute(); err != nil {\n    if strings.Contains(err.Error(), \"invalid value for flag poll\") {\n        // show usage: --poll accepts Go durations like 700ms, 2s, 1m\n    }\n    return err\n}","preventionTips":["Pass Go duration syntax to --poll (e.g. \"700ms\", \"2s\"), never bare numbers without units","Validate user-supplied intervals with time.ParseDuration before invoking Hugo","Document accepted duration formats in your wrapper's help text"],"tags":["hugo","cli","flags","file-watcher","duration-parsing"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}