lima-vm/lima · error

could not execute editor %#q for a file %#q: %w

Error message

could not execute editor %#q for a file %#q: %w

What it means

OpenEditor successfully located and launched the editor, but the editor process exited with a non-zero status. The error wraps the editor command, the temp YAML path, and the underlying exit error so the user can see which editor failed on which file.

Source

Thrown at pkg/editutil/editutil.go:86

	}
	tmpYAMLPath := tmpYAMLFile.Name()
	defer os.RemoveAll(tmpYAMLPath)
	if _, err := tmpYAMLFile.Write(append([]byte(hdr), content...)); err != nil {
		tmpYAMLFile.Close()
		return nil, err
	}
	if err := tmpYAMLFile.Close(); err != nil {
		return nil, err
	}

	editorCmd := exec.CommandContext(ctx, editor, tmpYAMLPath)
	editorCmd.Env = os.Environ()
	editorCmd.Stdin = os.Stdin
	editorCmd.Stdout = os.Stdout
	editorCmd.Stderr = os.Stderr
	logrus.Debugf("opening editor %#q for a file %#q", editor, tmpYAMLPath)
	if err := editorCmd.Run(); err != nil {
		return nil, fmt.Errorf("could not execute editor %#q for a file %#q: %w", editor, tmpYAMLPath, err)
	}
	b, err := os.ReadFile(tmpYAMLPath)
	if err != nil {
		return nil, err
	}
	modifiedInclHdr := string(b)
	modifiedExclHdr := strings.TrimPrefix(modifiedInclHdr, hdr)
	if strings.TrimSpace(modifiedExclHdr) == "" {
		return nil, nil
	}
	return []byte(modifiedExclHdr), nil
}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Check the wrapped exit error to see how the editor failed
  2. Set EDITOR to a terminal editor executable path without shell syntax, e.g. `export EDITOR=/usr/bin/vim`
  3. For GUI editors use a wait-wrapping wrapper (e.g. a script calling `code --wait`)
  4. Retry the edit command after fixing the EDITOR setting

Example fix

// before
export EDITOR="code"        // exits immediately, no wait
// after
export EDITOR="code --wait"  // via wrapper script if -- args unsupported
Defensive patterns

Strategy: try-catch

Validate before calling

editor := os.Getenv("EDITOR")
if editor != "" {
    if _, err := exec.LookPath(strings.Fields(editor)[0]); err != nil {
        return fmt.Errorf("EDITOR %q is not an executable", editor)
    }
}

Try / catch

content, err := editutil.OpenEditor(ctx, yaml, hdr)
if err != nil {
    var ee *exec.ExitError
    if errors.As(err, &ee) {
        return fmt.Errorf("editor exited non-zero (did it crash or not wait?): %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: The editor binary launched by OpenEditor (editAction / chooseNextCreatorState flows) exits non-zero — e.g. bad $EDITOR value (a flag-taking command like `code -w` misconfigured), editor crashing, or user quitting the editor with an error exit code.

Common situations: Setting EDITOR to a GUI editor that doesn't block/wait for the terminal; EDITOR containing shell syntax (pipes, args) that exec can't run directly; editor failing on the temp file's permissions or disk-full conditions.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/98d8924ac5423b95. Report an issue: GitHub.