{"record":{"id":"c7859332b8297522","repo":"kovidgoyal/kitty","slug":"the-env-directive-must-not-be-empty","errorCode":null,"errorMessage":"The env directive must not be empty","messagePattern":"The env directive must not be empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/ssh/config.go","lineNumber":163,"sourceCode":"}\n\nfunc ParseEnvInstruction(spec string) (ans []*EnvInstruction, err error) {\n\tconst COPY_FROM_LOCAL string = \"_kitty_copy_env_var_\"\n\tei := &EnvInstruction{}\n\tfound := false\n\tei.key, ei.val, found = strings.Cut(spec, \"=\")\n\tei.key = strings.TrimSpace(ei.key)\n\tif found {\n\t\tei.val = strings.TrimSpace(ei.val)\n\t\tif ei.val == COPY_FROM_LOCAL {\n\t\t\tei.val = \"\"\n\t\t\tei.copy_from_local = true\n\t\t}\n\t} else {\n\t\tei.delete_on_remote = true\n\t}\n\tif ei.key == \"\" {\n\t\terr = fmt.Errorf(\"The env directive must not be empty\")\n\t}\n\tans = []*EnvInstruction{ei}\n\treturn\n}\n\nvar paths_ctx *paths.Ctx\n\nfunc resolve_file_spec(spec string, is_glob bool) ([]string, error) {\n\tif paths_ctx == nil {\n\t\tpaths_ctx = &paths.Ctx{}\n\t}\n\tans := os.ExpandEnv(paths_ctx.ExpandHome(spec))\n\tif !filepath.IsAbs(ans) {\n\t\tans = paths_ctx.AbspathFromHome(ans)\n\t}\n\tif is_glob {\n\t\tfiles, err := doublestar.FilepathGlob(ans)\n\t\tif err != nil {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/ssh/config.go#L145-L181","documentation":"ParseEnvInstruction parses an env VAR=value or copy/delete directive; after building the EnvInstruction it verifies that the key is non-empty. An empty directive (or one that reduces to an empty variable name) triggers this error.","triggerScenarios":"Passing 'env ' with an empty string, a directive like '=' with no variable name, or whitespace-only content after the env keyword.","commonSituations":"Trailing empty env entries from templating/loops generating config lines, or trailing whitespace creating an empty final entry after splitting.","solutions":["Remove empty entries from the env list","Guard generators: skip env entries where strings.TrimSpace(entry) == \"\"","Validate the variable name is present before the '='"],"exampleFix":"// before\nenv: [\"PATH=/usr/bin\", \"\"]\n// after\nenv: [\"PATH=/usr/bin\"]","handlingStrategy":"validation","validationCode":"entries := slices.DeleteFunc(entries, func(e string) bool { return strings.TrimSpace(e) == \"\" })","typeGuard":"func isNonEmptyEnvEntry(e string) bool { return strings.TrimSpace(e) != \"\" && strings.SplitN(e, \"=\", 2)[0] != \"\" }","tryCatchPattern":null,"preventionTips":["Filter empty entries when generating env lists","Validate VAR names exist before '='"],"tags":["config","env","validation","ssh"],"backgroundTag":"empty-config-value","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}