{"record":{"id":"f7de3ae7a411b7ce","repo":"charmbracelet/crush","slug":"failed-to-get-lsp-diagnostics-status-code-d","errorCode":null,"errorMessage":"failed to get LSP diagnostics: status code %d","messagePattern":"failed to get LSP diagnostics: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":288,"sourceCode":"\t\treturn false\n\t}\n\tselect {\n\tcase evc <- ev:\n\t\treturn true\n\tcase <-ctx.Done():\n\t\treturn false\n\t}\n}\n\n// GetLSPDiagnostics retrieves LSP diagnostics for a specific LSP client.\nfunc (c *Client) GetLSPDiagnostics(ctx context.Context, id string, lspName string) (map[protocol.DocumentURI][]protocol.Diagnostic, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/lsps/%s/diagnostics\", id, lspName), nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get LSP diagnostics: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to get LSP diagnostics: status code %d\", rsp.StatusCode)\n\t}\n\tvar diagnostics map[protocol.DocumentURI][]protocol.Diagnostic\n\tif err := json.NewDecoder(rsp.Body).Decode(&diagnostics); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode LSP diagnostics: %w\", err)\n\t}\n\treturn diagnostics, nil\n}\n\n// GetLSPs retrieves the LSP client states for a workspace.\nfunc (c *Client) GetLSPs(ctx context.Context, id string) (map[string]proto.LSPClientInfo, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/lsps\", id), nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get LSPs: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to get LSPs: status code %d\", rsp.StatusCode)\n\t}","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L270-L306","documentation":"GetLSPDiagnostics received an HTTP response but the status code was not 200. The server processed the request and rejected it (bad path/id, auth, server error), so no diagnostics payload is decoded. The code is reported in the message.","triggerScenarios":"Calling GetLSPDiagnostics against a workspace id or lsp name that doesn't exist (404), an unauthorized/expired session (401/403), or a server-side crash (500) on the /workspaces/{id}/lsps/{lspName}/diagnostics endpoint.","commonSituations":"Typo in the LSP name or querying before the LSP has started; workspace session ended so the id is stale; proxy/auth middleware returning 401; server version lacking the diagnostics endpoint (404/405).","solutions":["Log/handle rsp status: confirm the workspace id exists via GetWorkspace and the LSP name matches one returned by GetLSPs.","Re-authenticate if you received 401/403.","Ensure the LSP server is started for that workspace before querying diagnostics.","Check server logs for the 5xx cause if status >= 500."],"exampleFix":"// before\ndiags, err := client.GetLSPDiagnostics(ctx, wsID, \"gopls\")\n// after\ndiags, err := client.GetLSPDiagnostics(ctx, wsID, \"gopls\")\nif err != nil {\n    if strings.Contains(err.Error(), \"status code 404\") {\n        return nil, fmt.Errorf(\"LSP %q not found in workspace %s\", lspName, wsID)\n    }\n    return nil, err\n}","handlingStrategy":"fallback","validationCode":"ws, err := client.GetWorkspace(ctx, wsID); if err != nil { return err }\nlsps, err := client.GetLSPs(ctx, wsID); if err != nil { return err }\nif _, ok := lsps[lspName]; !ok { return fmt.Errorf(\"LSP %q not running in workspace\", lspName) }","typeGuard":"func isStatusErr(err error) (int, bool) {\n\tvar se interface{ StatusCode() int }\n\tif err != nil && errors.As(err, &se) { return se.StatusCode(), true }\n\treturn 0, false\n}","tryCatchPattern":"diags, err := client.GetLSPDiagnostics(ctx, wsID, lspName)\nif err != nil {\n\tif code, ok := isStatusErr(err); ok && code == http.StatusNotFound {\n\t\treturn emptyDiagnostics, nil // no LSP/diagnostics yet — degrade gracefully\n\t}\n\treturn nil, err\n}","preventionTips":["Confirm the LSP is started (GetLSPs) before querying its diagnostics.","Handle 401 by refreshing credentials proactively.","Keep client and server versions aligned so endpoints exist.","Return empty diagnostics instead of failing when a status 404 means 'nothing yet'."],"tags":["http-status","lsp","api","go"],"backgroundTag":"http-non-200-status","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}