twpayne/chezmoi · error

%s: unknown entry type

Error message

%s: unknown entry type

What it means

EntryTypeSet.SetSlice parses entry type strings like 'file', 'dir', 'symlink', optionally prefixed with 'no' to exclude. If an element is not a known entry type bit, this error names the unrecognized element. It guards the set from accepting invalid type names.

Source

Thrown at internal/chezmoi/entrytypeset.go:304

func (s *EntryTypeSet) Set(str string) error {
	if str == "none" {
		s.bits = EntryTypesNone
		return nil
	}
	return s.SetSlice(strings.Split(str, ","))
}

// SetSlice sets s from a []string.
func (s *EntryTypeSet) SetSlice(ss []string) error {
	bits := EntryTypesNone
	for i, element := range ss {
		if element == "" {
			continue
		}
		element, exclude := strings.CutPrefix(element, "no")
		bit, ok := entryTypeBits[element]
		if !ok {
			return fmt.Errorf("%s: unknown entry type", element)
		}
		if i == 0 && exclude {
			bits = EntryTypesAll
		}
		if exclude {
			bits &^= bit
		} else {
			bits |= bit
		}
	}
	s.bits = bits
	return nil
}

// String implements github.com/spf13/pflag.Value.String.
func (s *EntryTypeSet) String() string {
	if s == nil {
		return "none"

View on GitHub (pinned to f901167e46)

Solutions

  1. Correct the element to a valid entry type (e.g. 'file', 'dir', 'symlink', 'remove', 'script', 'once')
  2. Remove the invalid element from the slice
  3. Check docs for the chezmoi version in use, as the accepted set of types may differ across versions

Example fix

// before
entryTypeSet.SetSlice([]string{"files", "dirs"})

// after
entryTypeSet.SetSlice([]string{"file", "dir"})
Defensive patterns

Strategy: validation

Validate before calling

validTypes := map[string]bool{"file":true,"dir":true,"symlink":true,"remove":true,"script":true}
for _, el := range elems {
    name := strings.TrimPrefix(el, "no")
    if !validTypes[name] { return fmt.Errorf("invalid entry type %q", el) }
}

Try / catch

if err := set.SetSlice(elems); err != nil {
    if strings.Contains(err.Error(), "unknown entry type") {
        // report the invalid element from the error message
    }
}

Prevention

When it happens

Trigger: Calling SetSlice (directly or via Set) with an element string not present in entryTypeBits, e.g. a typo like 'files', 'dirs', or an empty-to-nonempty element that isn't a valid type.

Common situations: Typo in .chezmoiignore or script-generated patterns using entry types, hand-written attribute strings in templates, version drift where an expected type name changed.

Related errors


AI-assisted analysis of twpayne/chezmoi@f901167e46 (2026-09-01). Data as JSON: /api/errors/7908a6c3b4e551b4. Report an issue: GitHub.