twpayne/chezmoi · error

empty filename

Error message

empty filename

What it means

errEmptyFilename is a sentinel error in internal/chezmoi/attr.go:12. parseFileAttr returns it when the file name being parsed is an empty string. File names in the source state carry target attributes (immutable, encrypted, script type prefixes), so an empty name is not a valid source file entry.

Source

Thrown at internal/chezmoi/attr.go:12

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
)

var sourceFileTypeStrs = map[SourceFileTargetType]string{

View on GitHub (pinned to f901167e46)

Solutions

  1. Inspect the source directory and remove/fix entries with empty basenames.
  2. Ensure file names are non-empty before calling parseFileAttr.
  3. Use a properly prefixed file name (e.g. run_, exact_, etc.) so attributes parse correctly.

Example fix

// before
attr := chezmoi.ParseFileAttr(name)
// after
if name == "" {
    return nil, errors.New("file name is empty")
}
attr := chezmoi.ParseFileAttr(name)
Defensive patterns

Strategy: validation

Validate before calling

if name == "" {
    return fmt.Errorf("skipping source file entry: empty name")
}

Prevention

When it happens

Trigger: Calling parseFileAttr with an empty string, e.g. when enumerating source files and a basename is empty.

Common situations: Manually renamed or corrupted files in ~/.local/share/chezmoi; scripts generating source entries with empty names; misconfigured source directory templates.

Related errors


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