{"record":{"id":"1d9b7eb6a3d9dd6c","repo":"charmbracelet/crush","slug":"invalid-lsp-command-w","errorCode":null,"errorMessage":"invalid lsp command: %w","messagePattern":"invalid lsp command: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lsp/client.go","lineNumber":193,"sourceCode":"\t\tdone <- c.client.Exit()\n\t}()\n\n\tselect {\n\tcase err := <-done:\n\t\treturn err\n\tcase <-closeCtx.Done():\n\t\tc.client.Kill()\n\t\treturn closeCtx.Err()\n\t}\n}\n\n// createPowernapClient creates a new powernap client with the current configuration.\nfunc (c *Client) createPowernapClient() error {\n\trootURI := string(protocol.URIFromPath(c.cwd))\n\n\tcommand, err := c.resolver.ResolveValue(c.config.Command)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid lsp command: %w\", err)\n\t}\n\n\targs, err := c.config.ResolvedArgs(c.resolver)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid lsp args: %w\", err)\n\t}\n\n\tenvs, err := c.config.ResolvedEnv(c.resolver)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid lsp env: %w\", err)\n\t}\n\n\tclientConfig := powernap.ClientConfig{\n\t\tCommand:     home.Long(command),\n\t\tArgs:        args,\n\t\tRootURI:     rootURI,\n\t\tEnvironment: envs,\n\t\tSettings:    c.config.Options,","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/lsp/client.go#L175-L211","documentation":"createPowernapClient calls resolver.ResolveValue on c.config.Command before spawning the LSP server process. When the command string contains shell/template expansions (e.g. environment variables, ~, config placeholders) that cannot be resolved, it returns this wrapped error. It indicates the LSP server command is not a concrete executable path/word after resolution, so no client can be created.","triggerScenarios":"Calling New or Restart on an lsp.Client whose config.Command contains an unresolvable expansion — e.g. an env var that is unset at expansion time, or a resolver that fails on the configured command string.","commonSituations":"crush config defines an LSP command like \"${GoplsPath}\" or \"$HOME/bin/gopls\" but the variable is not exported in the environment where crush runs; command typo'd or left empty; command defined in a config file that assumes a different shell environment.","solutions":["Set/verify the environment variables referenced in the configured LSP command before starting crush.","Replace the templated command with an absolute executable path (e.g. /usr/local/bin/gopls) in the LSP config.","Check that the command value in the LSP config is non-empty and correctly spelled.","Run the command string manually in a shell to confirm it expands to a valid executable."],"exampleFix":"// before\ncommand = \"${MY_GOPLS}/gopls\" // MY_GOPLS not set\n\n// after\ncommand = \"/usr/local/bin/gopls\" // or export MY_GOPLS first","handlingStrategy":"validation","validationCode":"cmd := os.ExpandEnv(lspCfg.Command)\nif strings.TrimSpace(cmd) == \"\" {\n    return fmt.Errorf(\"lsp command resolves to empty string: %q\", lspCfg.Command)\n}\nif _, err := exec.LookPath(cmd); err != nil {\n    return fmt.Errorf(\"lsp command %q not found on PATH\", cmd)\n}","typeGuard":"func validLSPCommand(cfg LSPConfig) bool {\n    return cfg.Command != \"\" && !strings.Contains(cfg.Command, \"${\")\n}","tryCatchPattern":"client, err := lsp.New(cfg)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid lsp command\") {\n        slog.Error(\"Check the lsp command and its env expansions\", \"command\", cfg.Command, \"error\", err)\n    }\n    return err\n}","preventionTips":["Use absolute paths for LSP server commands in shared configs.","Document required env vars next to the LSP config and set them in CI/containers.","Smoke-test config resolution with a startup check that runs exec.LookPath early."],"tags":["lsp","config","command-resolution"],"backgroundTag":"command-resolution-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}