twpayne/chezmoi · error
empty directory name
Error message
empty directory name
What it means
errEmptyDirName is a sentinel error in chezmoi's source attribute parsing (internal/chezmoi/attr.go:11). parseDirAttr returns it when the directory name being parsed is an empty string. Directory names in chezmoi's source state encode target attributes (prefixes, literal markers), so an empty name cannot be interpreted as any valid target path.
Source
Thrown at internal/chezmoi/attr.go:11
package chezmoi
import (
"errors"
"io/fs"
"log/slog"
"strings"
)
var (
errEmptyDirName = errors.New("empty directory name")
errEmptyFilename = errors.New("empty filename")
)
// A SourceFileTargetType is a the type of a target represented by a file in the
// source state. A file in the source state can represent a file, script, or
// symlink in the target state.
type SourceFileTargetType int
// Source file types.
const (
SourceFileTypeCreate SourceFileTargetType = iota
SourceFileTypeFile
SourceFileTypeModify
SourceFileTypeRemove
SourceFileTypeScript
SourceFileTypeSymlink
)
View on GitHub (pinned to f901167e46)
Solutions
- Check the source state directory entries; find and fix or remove the entry with an empty base name.
- Validate directory names are non-empty before passing them to parseDirAttr orchezmoi source-state APIs.
- Re-create the affected source directory with a valid attribute-encoded name.
Example fix
// before
chezmoi.ParseDirAttr("")
// after
if name == "" {
return fmt.Errorf("cannot parse dir attr: name is empty")
}
attr := chezmoi.ParseDirAttr(name) Defensive patterns
Strategy: validation
Validate before calling
if name == "" {
return fmt.Errorf("skipping source dir entry: empty name")
} Prevention
- Skip entries with empty basenames before parsing attributes.
- Keep source state directories managed by chezmoi; avoid manual edits.
- Validate source directory contents after restores or syncs.
When it happens
Trigger: Calling parseDirAttr with an empty string as the directory name, e.g. when walking a source state where a directory entry yields a zero-length base name.
Common situations: Corrupted or hand-edited source state directories; filesystem oddities producing empty base names; programmatic construction of source state entries without validation.
Related errors
- empty filename
- %s: unknown entry type
- %s: parse error
- %s: invalid pattern
- %s: parent directory not in source state
AI-assisted analysis of twpayne/chezmoi@f901167e46 (2026-09-01).
Data as JSON: /api/errors/62effe1d1bee0dea.
Report an issue: GitHub.