gohugoio/hugo · error

invalid deployment.target.exclude

Error message

invalid deployment.target.exclude %q: %v

What it means

Symmetric to Include: Target.ParseIncludeExclude (deploy/deployconfig/deployConfig.go:88) compiles the target's Exclude field via hglob.GetGlob and wraps a parse failure. The Exclude field removes files from a target's upload set.

Solutions

  1. Validate the Exclude value as a glob; prefer simple patterns like '**/*.map'.
  2. Remember include/exclude are globs (hglob), not regex.
  3. Balance any brackets/braces in the pattern.

Example fix

# before
[[deployment.targets]]
name = "cdn"
exclude = "(*.map"   # unbalanced paren

# after
[[deployment.targets]]
name = "cdn"
exclude = "**/*.map"
Defensive patterns

Strategy: validation

Validate before calling

import "github.com/gohugoio/hugo/hugofs/hglob"

func ValidateExcludeGlob(pattern string) error {
    if pattern == "" { return nil }
    _, err := hglob.GetGlob(pattern)
    return err
}

Try / catch

if err := tgt.ParseIncludeExclude(); err != nil {
    return err
}

Prevention

When it happens

Trigger: Setting `exclude` on a [[deployment.targets]] entry to a value hglob cannot parse (unclosed bracket, malformed brace expansion, etc.).

Common situations: Confusing glob and regex syntax in exclude; an unclosed character class.

Related errors


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

Appendix: 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 52c9bd7908)