micro-editor/micro · error
Parent dirs don't exist, enable 'mkparents' for auto creatio
Error message
Parent dirs don't exist, enable 'mkparents' for auto creation
What it means
Thrown by buffer save when the leading directory of the absolute target path does not exist (os.Stat(dirname) returns fs.ErrNotExist) and the 'mkparents' setting is false. Micro deliberately refuses to silently create missing parent directories unless the user opted in via mkparents.
Source
Thrown at internal/buffer/save.go:300
if err == nil && !fileInfo.Mode().IsRegular() {
return errors.New("Error: " + filename + " is not a regular file and cannot be saved")
}
absFilename := util.ResolvePath(filename)
// Get the leading path to the file | "." is returned if there's no leading path provided
if dirname := filepath.Dir(absFilename); dirname != "." {
// Check if the parent dirs don't exist
if _, statErr := os.Stat(dirname); errors.Is(statErr, fs.ErrNotExist) {
// Prompt to make sure they want to create the dirs that are missing
if b.Settings["mkparents"].(bool) {
// Create all leading dir(s) since they don't exist
if mkdirallErr := os.MkdirAll(dirname, os.ModePerm); mkdirallErr != nil {
// If there was an error creating the dirs
return mkdirallErr
}
} else {
return errors.New("Parent dirs don't exist, enable 'mkparents' for auto creation")
}
}
}
saveResponseChan := make(chan saveResponse)
saveRequestChan <- saveRequest{b, absFilename, withSudo, newFile, saveResponseChan}
result := <-saveResponseChan
err = result.err
if err != nil {
if errors.Is(err, util.ErrOverwrite) {
screen.TermMessage(err)
err = errors.Unwrap(err)
b.UpdateModTime()
}
return err
}
View on GitHub (pinned to 1c8b82b32e)
Solutions
- Enable the option: run `set mkparents true` (persist by adding "mkparents": true to settings.json), then retry the save.
- Or create the directory yourself first: mkdir -p <parent-dir>, then save again.
- Or fix the typo in the path — check each directory component with ls.
- If embedding micro, set the mkparents buffer/global setting programmatically before SaveAs.
Example fix
// before (~/.config/micro/settings.json):
{ "mkparents": false }
// save as newdir/file.go -> error
// after:
{ "mkparents": true }
// save as newdir/file.go -> parents created, save succeeds Defensive patterns
Strategy: validation
Validate before calling
func ensureParentDir(path string, mkparents bool) error {
dir := filepath.Dir(util.ResolvePath(path))
if dir == "." {
return nil
}
if _, err := os.Stat(dir); errors.Is(err, fs.ErrNotExist) {
if !mkparents {
return os.MkdirAll(dir, 0o755) // or surface a prompt to the user
}
}
return nil
}
// run before buf.SaveAs(path) Try / catch
if err := buf.Save(); err != nil {
if strings.Contains(err.Error(), "enable 'mkparents'") {
_ = config.SetGlobalOption("mkparents", true)
// user re-triggers save, or call buf.Save() again
}
} Prevention
- Set "mkparents": true once in settings.json if you regularly create new directory trees from the editor.
- Alternatively mkdir -p the target tree from your shell before saving into it.
- Double-check directory components for typos before hitting enter on SaveAs.
When it happens
Trigger: SaveAs to 'newproj/src/main.go' when 'newproj/src' does not exist, with the mkparents option left at its default false. The check runs in internal/buffer/save.go:300 right after util.ResolvePath/filepath.Dir computes the parent; any missing intermediate directory triggers it.
Common situations: Starting a new project layout from inside micro, saving into a not-yet-cloned repo path, or a typo in a directory component ('~/Documnets/file.txt'). Users coming from editors that auto-create directories hit this most.
Related errors
- Error: %s is a directory and cannot be saved
- Error: %s is not a regular file and cannot be saved
- bindings is locked by the user
- Error reading bindings.json file: %s
- Error: %s is a directory and cannot be opened
AI-assisted analysis of micro-editor/micro@1c8b82b32e (2026-08-15).
Data as JSON: /api/errors/b2995d16c294f8da.
Report an issue: GitHub.