gohugoio/hugo · info

errHelp

errHelp

Error message

help requested

What it means

`errHelp` is a sentinel error (`errors.New("help requested")`) used internally by Hugo's command layer (simplecobra wiring in `commandeer.go`) to signal that the user asked for help (`-h`/`--help` or bare invocation). It is not a real failure — callers compare against it to print usage and exit with success instead of reporting an error.

Source

Thrown at commands/commandeer.go:58

	"github.com/gohugoio/hugo/common/hstrings"
	"github.com/gohugoio/hugo/common/htime"
	"github.com/gohugoio/hugo/common/hugo"
	"github.com/gohugoio/hugo/common/loggers"
	"github.com/gohugoio/hugo/common/paths"
	"github.com/gohugoio/hugo/common/types"
	"github.com/gohugoio/hugo/config"
	"github.com/gohugoio/hugo/config/allconfig"
	"github.com/gohugoio/hugo/deps"
	"github.com/gohugoio/hugo/helpers"
	"github.com/gohugoio/hugo/hugofs"
	"github.com/gohugoio/hugo/hugolib"
	"github.com/gohugoio/hugo/identity"
	"github.com/gohugoio/hugo/resources/kinds"
	"github.com/spf13/afero"
	"github.com/spf13/cobra"
)

var errHelp = errors.New("help requested")

// Execute executes a command.
func Execute(args []string) error {
	// Default GOMAXPROCS to be CPU limit aware, still respecting GOMAXPROCS env.
	maxprocs.Set()
	x, err := newExec()
	if err != nil {
		return err
	}
	args = mapLegacyArgs(args)
	cd, err := x.Execute(context.Background(), args)
	if cd != nil {
		if closer, ok := cd.Root.Command.(types.Closer); ok {
			closer.Close()
		}
	}

	if err != nil {

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. If you see this surfaced as an error, check the call site for a missing `errors.Is(err, errHelp)` guard and treat it as a clean exit.
  2. When embedding the commands package, filter this sentinel before logging errors from Execute.

Example fix

// before
if err := commands.Execute(args); err != nil { log.Fatal(err) }
// after
if err := commands.Execute(args); err != nil && !errors.Is(err, errHelp) { log.Fatal(err) }
Defensive patterns

Strategy: type-guard

Type guard

// errHelp is a sentinel meaning --help was shown; not a real failure
if errors.Is(err, errHelp) {
    os.Exit(0)
}

Try / catch

err := commandeer.Execute(args)
switch {
case err == nil:
case errors.Is(err, errHelp):
    // help text already printed; exit success
default:
    log.Fatal(err)
}

Prevention

When it happens

Trigger: Running `hugo --help`, `hugo <subcommand> -h`, or a command form that cobra resolves to a help request; the execution path returns `errHelp` up the stack where `Execute` intercepts it.

Common situations: Only visible to developers embedding or extending Hugo's `commands` package who propagate the error without checking `errors.Is(err, errHelp)`; end users never see this text in normal operation.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/55fc269fb4ea55e8.json. Report an issue: GitHub ↗.