gohugoio/hugo · error

invalid deployment.target.exclude %q: %v

Error message

invalid deployment.target.exclude %q: %v

What it means

The exclude-side twin of error 367: `Target.ParseIncludeExclude` compiles the target's `exclude` string with `hglob.GetGlob` and returns this wrapped error when the pattern is not a valid gobwas/glob expression. Deployment aborts at config-decode time rather than mid-upload.

Source

Thrown at deploy/deployconfig/deployConfig.go:90

	// If true, any local path matching <dir>/index.html will be mapped to the
	// remote path <dir>/. This does not affect the top-level index.html file,
	// since that would result in an empty path.
	StripIndexHTML bool
}

func (tgt *Target) ParseIncludeExclude() error {
	var err error
	if tgt.Include != "" {
		tgt.IncludeGlob, err = hglob.GetGlob(tgt.Include)
		if err != nil {
			return fmt.Errorf("invalid deployment.target.include %q: %v", tgt.Include, err)
		}
	}
	if tgt.Exclude != "" {
		tgt.ExcludeGlob, err = hglob.GetGlob(tgt.Exclude)
		if err != nil {
			return fmt.Errorf("invalid deployment.target.exclude %q: %v", tgt.Exclude, err)
		}
	}
	return nil
}

// Matcher represents configuration to be applied to files whose paths match
// a specified pattern.
type Matcher struct {
	// Pattern is the string pattern to match against paths.
	// Matching is done against paths converted to use / as the path separator.
	Pattern string

	// CacheControl specifies caching attributes to use when serving the blob.
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
	CacheControl string

	// ContentEncoding specifies the encoding used for the blob's content, if any.
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Correct the glob in the target's `exclude` setting — e.g. `"**.{gif,jpg}"` with the closing brace.
  2. Stick to gobwas/glob syntax; separate alternatives with commas inside `{}` and close all groups.
  3. Verify with `hugo deploy --dryRun` before a real deploy.

Example fix

# before
[[deployment.targets]]
exclude = "**.[jpg"
# after
[[deployment.targets]]
exclude = "**.{jpg,gif}"
Defensive patterns

Strategy: validation

Validate before calling

if _, err := glob.Compile(excludePattern); err != nil {
    return fmt.Errorf("bad deployment.target.exclude %q: %w", excludePattern, err)
}

Prevention

When it happens

Trigger: `hugo deploy` with a deployment target whose `exclude` value fails gobwas/glob compilation — unbalanced `{`/`[`, or otherwise malformed pattern like `exclude = "**/[draft"`.

Common situations: Trying to exclude multiple extensions with malformed brace groups, using regex or gitignore syntax, or shell-quoting issues that truncate the pattern in the config file.

Related errors


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