charmbracelet/glow · error

unable to set config file: %w

Error message

unable to set config file: %w

What it means

The glow config command uses charmbracelet/editor's editor.Cmd("Glow", configFile) to build an exec.Cmd for the user's editor (resolved from $EDITOR and similar sources). This error wraps the failure to construct that command, before anything is spawned — typically because no usable editor could be resolved. The editor binary itself has not run yet when this fires.

Source

Thrown at config_cmd.go:42

# show all files, including hidden and ignored.
all: false
`

var configCmd = &cobra.Command{
	Use:     "config",
	Hidden:  false,
	Short:   "Edit the glow config file",
	Long:    paragraph(fmt.Sprintf("\n%s the glow config file. We’ll use EDITOR to determine which editor to use. If the config file doesn't exist, it will be created.", keyword("Edit"))),
	Example: paragraph("glow config\nglow config --config path/to/config.yml"),
	Args:    cobra.NoArgs,
	RunE: func(*cobra.Command, []string) error {
		if err := ensureConfigFile(); err != nil {
			return err
		}

		c, err := editor.Cmd("Glow", configFile)
		if err != nil {
			return fmt.Errorf("unable to set config file: %w", err)
		}
		c.Stdin = os.Stdin
		c.Stdout = os.Stdout
		c.Stderr = os.Stderr
		if err := c.Run(); err != nil {
			return fmt.Errorf("unable to run command: %w", err)
		}

		fmt.Println("Wrote config file to:", configFile)
		return nil
	},
}

func ensureConfigFile() error {
	if configFile == "" {
		configFile = viper.GetViper().ConfigFileUsed()
		if err := os.MkdirAll(filepath.Dir(configFile), 0o755); err != nil { //nolint:gosec
			return fmt.Errorf("could not write configuration file: %w", err)

View on GitHub (pinned to e3970c813d)

Solutions

  1. Export a valid editor: export EDITOR=vim (or nano, micro)
  2. Verify it resolves: command -v $EDITOR
  3. Install a terminal editor if the image has none (apt-get install vim-tiny)
  4. Alternatively edit the file directly: ${EDITOR:-vi} ~/.config/glow/glow.yml

Example fix

# before
$ unset EDITOR; glow config
# Error: unable to set config file: ...

# after
$ export EDITOR=vim && glow config
Defensive patterns

Strategy: validation

Validate before calling

func resolveEditor() (string, error) {
	ed := os.Getenv("EDITOR")
	if ed == "" {
		return "", errors.New("EDITOR is not set; export EDITOR=<editor> before 'glow config'")
	}
	bin := strings.Fields(ed)[0]
	if _, err := exec.LookPath(bin); err != nil {
		return "", fmt.Errorf("editor %q not found on PATH: %w", bin, err)
	}
	return ed, nil
}

if _, err := resolveEditor(); err != nil {
	log.Fatal(err)
}

Try / catch

if err := configCmd.Execute(); err != nil {
	if strings.Contains(err.Error(), "unable to set config file") {
		// environment problem, not a glow bug: surface the EDITOR hint
		fmt.Fprintln(os.Stderr, "set EDITOR, e.g. export EDITOR=vim, then retry")
		os.Exit(1)
	}
	return err
}

Prevention

When it happens

Trigger: Running glow config with EDITOR unset or empty in a minimal environment where no fallback editor is found; EDITOR pointing to a command name that cannot be resolved on PATH at lookup time; EDITOR containing a malformed value.

Common situations: Docker/scratch containers and CI shells with no EDITOR exported; headless servers where the dotfiles that set EDITOR were never installed; EDITOR set to an editor that was later uninstalled.

Related errors


AI-assisted analysis of charmbracelet/glow@e3970c813d (2026-08-15). Data as JSON: /api/errors/0698a1c0e98eb55a. Report an issue: GitHub.