sipeed/picoclaw · error

failed to parse $EDITOR: %w

Error message

failed to parse $EDITOR: %w

What it means

The EDITOR value is split with shlex (edit.go:33-36) so multi-word values like `code --wait` work; if the shell-style string is malformed — classically unbalanced quotes — shlex.Split returns an error, wrapped here with %w. The parse happens after the config was validated, so no state is changed.

Source

Thrown at cmd/picoclaw/internal/mcp/edit.go:35

		Short: "Open the PicoClaw config in $EDITOR",
		Args:  cobra.NoArgs,
		RunE: func(cmd *cobra.Command, _ []string) error {
			editor := strings.TrimSpace(os.Getenv("EDITOR"))
			if editor == "" {
				return fmt.Errorf("$EDITOR is not set")
			}

			cfg, err := loadConfig()
			if err != nil {
				return err
			}
			if err = saveValidatedConfig(cfg); err != nil {
				return err
			}

			editorArgs, err := shlex.Split(editor)
			if err != nil {
				return fmt.Errorf("failed to parse $EDITOR: %w", err)
			}
			if len(editorArgs) == 0 {
				return fmt.Errorf("$EDITOR is empty")
			}

			editorArgs = append(editorArgs, internal.GetConfigPath())
			process := editorCommand(editorArgs[0], editorArgs[1:]...)
			process.Stdin = cmd.InOrStdin()
			process.Stdout = cmd.OutOrStdout()
			process.Stderr = cmd.ErrOrStderr()

			if err := process.Run(); err != nil {
				return fmt.Errorf("failed to start editor: %w", err)
			}

			return nil
		},
	}

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Fix the quoting in EDITOR, or simplify it to a single word (vim, nano)
  2. Move flags into a wrapper script and set EDITOR to the script path
  3. Verify interactively: run "$EDITOR" (with the quotes echoed via printf '%s\n' "$EDITOR") before retrying

Example fix

# before
export EDITOR='code --wait "unclosed'
# after
export EDITOR='code --wait'
Defensive patterns

Strategy: validation

Validate before calling

import "github.com/google/shlex"

if _, err := shlex.Split(editor); err != nil {
	return fmt.Errorf("EDITOR %q is not valid shell syntax: %w", editor, err)
}

Prevention

When it happens

Trigger: export EDITOR='vim -c "set ro' (missing closing quote); a dangling backslash; control characters pasted from another terminal.

Common situations: Hand-editing dotfiles and leaving an unclosed quote; copying an EDITOR line whose quoting was written for a different shell; nested quoting over SSH.

Understand the failure class

Related errors


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/1432bd23007ced39. Report an issue: GitHub.