{"record":{"id":"15642f85e8ad74cf","repo":"ipfs/kubo","slug":"cannot-parse-editor-value-s","errorCode":null,"errorMessage":"cannot parse $EDITOR value: %s","messagePattern":"cannot parse \\$EDITOR value: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/config.go","lineNumber":614,"sourceCode":"\t\treturn nil, fmt.Errorf(\"failed to set config value: %s (maybe use --json?)\", err)\n\t}\n\treturn getConfig(r, key)\n}\n\n// parseEditorCommand parses the EDITOR environment variable into command and arguments\nfunc parseEditorCommand(editor string) ([]string, error) {\n\treturn shlex.Split(editor, true)\n}\n\nfunc editConfig(filename string) error {\n\teditor := os.Getenv(\"EDITOR\")\n\tif editor == \"\" {\n\t\treturn errors.New(\"ENV variable $EDITOR not set\")\n\t}\n\n\teditorAndArgs, err := parseEditorCommand(editor)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot parse $EDITOR value: %s\", err)\n\t}\n\teditor = editorAndArgs[0]\n\targs := append(editorAndArgs[1:], filename)\n\n\tcmd := exec.Command(editor, args...)\n\tcmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr\n\treturn cmd.Run()\n}\n\n// nodePeerID derives the PeerID implied by the private key stored in the repo\n// config. Identity.PeerID must equal this value; the node refuses to start\n// when the two disagree.\nfunc nodePeerID(r repo.Repo) (peer.ID, error) {\n\tkeyF, err := getConfig(r, config.PrivKeySelector)\n\tif err != nil {\n\t\treturn \"\", errors.New(\"failed to get PrivKey\")\n\t}\n\tpkstr, ok := keyF.Value.(string)","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/config.go#L596-L632","documentation":"`editConfig` parses $EDITOR with shlex (shell-style word splitting) so values like 'code -w' become command + args. This error wraps a shlex failure — raised when the EDITOR value contains unbalanced quotes or other characters that cannot be tokenized. The wrapped shlex error is included via %s.","triggerScenarios":"EDITOR set to a value with unbalanced quotes, e.g. `EDITOR='vim \"'` or other malformed shell-like strings that shlex.Split cannot parse into tokens.","commonSituations":"Users quoting paths with mismatched quotes (EDITOR=\"'/usr/local/bin/my editor\"), or copy-pasting an EDITOR value with stray quote characters into their shell rc file.","solutions":["Fix the EDITOR value to be simple or correctly quoted: `EDITOR='code -w'` (balanced quotes)","Test the split first: `echo $EDITOR` and verify it's a clean command plus optional flags","Simplify to a bare binary name if possible: `EDITOR=vim`","If the editor path has spaces, create a symlink without spaces or use a wrapper script"],"exampleFix":"// before\nexport EDITOR='my editor -w   \"'\n// after\nexport EDITOR='code -w'","handlingStrategy":"validation","validationCode":"EDITOR='code -w'; python3 -c \"import shlex,sys; shlex.split(sys.argv[1])\" \"$EDITOR\" && echo \"EDITOR parses OK\"","typeGuard":null,"tryCatchPattern":"if err := editConfig(f); err != nil {\n    if strings.HasPrefix(err.Error(), \"cannot parse $EDITOR\") {\n        fmt.Fprintf(os.Stderr, \"fix EDITOR quoting; got: %q\\n\", os.Getenv(\"EDITOR\"))\n    }\n    return err\n}","preventionTips":["Keep EDITOR as a simple command name plus flags, e.g. EDITOR='code -w'","Quote paths with spaces using balanced single quotes in your rc file","Avoid copy-pasting EDITOR values with curly/smart quotes","Test with shlex or `echo` before relying on it in scripts"],"tags":["config","environment","parsing"],"backgroundTag":"env-var-parse-failed","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}