twpayne/chezmoi · error
%s: not found
Error message
%s: not found
What it means
When translating a target's actual state into a source-state entry (during chezmoi add), an ActualStateAbsent means the destination path does not exist on the filesystem, so there is nothing to add and chezmoi errors '<path>: not found'.
Source
Thrown at internal/chezmoi/sourcestate.go:3000
Have: s.version,
Need: *version,
}
}
return nil
}
// sourceStateEntry returns a new SourceStateEntry based on actualStateEntry.
func (s *SourceState) sourceStateEntry(
actualStateEntry ActualStateEntry,
destAbsPath AbsPath,
fileInfo fs.FileInfo,
parentSourceRelPath SourceRelPath,
targetRelPath RelPath,
options *AddOptions,
) (SourceStateEntry, error) {
switch actualStateEntry := actualStateEntry.(type) {
case *ActualStateAbsent:
return nil, fmt.Errorf("%s: not found", destAbsPath)
case *ActualStateDir:
return s.newSourceStateDirEntry(actualStateEntry, fileInfo, parentSourceRelPath, targetRelPath, options), nil
case *ActualStateFile:
return s.newSourceStateFileEntryFromFile(actualStateEntry, fileInfo, parentSourceRelPath, options)
case *ActualStateSymlink:
return s.newSourceStateFileEntryFromSymlink(actualStateEntry, fileInfo, parentSourceRelPath, options)
default:
panic(fmt.Sprintf("%T: unsupported type", actualStateEntry))
}
}
func (e *External) IsExternal() bool {
return true
}
func (e *External) OriginString() string {
urlStr := cmp.Or(append([]string{e.URL}, e.URLs...)...)
return urlStr + " defined in " + e.sourceAbsPath.String()View on GitHub (pinned to f901167e46)
Solutions
- Verify the path exists on the target system (ls the exact path chezmoi resolves)
- Recreate the file/directory before running chezmoi add
- Check spelling and that you are referencing the target path, not the source path
Example fix
// before chezmoi add ~/.zshrc # file was deleted // after touch ~/.zshrc # or restore it, then chezmoi add ~/.zshrc
Defensive patterns
Strategy: validation
Validate before calling
// check the target exists before `chezmoi add`
path := os.ExpandEnv("$HOME/.zshrc")
if _, err := os.Lstat(path); err != nil {
return fmt.Errorf("cannot add %s: %w", path, err)
} Type guard
func targetExists(absPath string) bool {
_, err := os.Lstat(absPath)
return err == nil
} Try / catch
if err := runAdd(targets); err != nil {
if strings.Contains(err.Error(), ": not found") {
return fmt.Errorf("target missing on filesystem; create it or fix the path: %w", err)
}
return err
} Prevention
- Verify the exact target path exists before running chezmoi add
- Watch for renames/deletes between generating the file and adding it
- Remember chezmoi add takes target paths (~/.foo), not source paths
When it happens
Trigger: Running chezmoi add with a target path that does not exist in the destination (typo, deleted file, or path relative to the wrong base directory).
Common situations: Adding a file after deleting or renaming it; typo in path passed to `chezmoi add`; assuming ~-relative resolution differs from actual target path; adding something managed only by a script.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- %s: not a directory
- %s: not a directory
- open %s: failed to acquire lock: %w
- %s: cannot add chezmoi's config file to chezmoi, use a confi
- %s: cannot add chezmoi file to chezmoi (%s is protected)
AI-assisted analysis of twpayne/chezmoi@f901167e46 (2026-09-01).
Data as JSON: /api/errors/53faeb17dbd98600.
Report an issue: GitHub.