{"record":{"id":"cc53e6a4952153bc","repo":"LykosAI/StabilityMatrix","slug":"the-name-key-was-not-found-in-the-pip-show-output","errorCode":null,"errorMessage":"The 'Name' key was not found in the pip show output.","messagePattern":"The 'Name' key was not found in the pip show output\\.","errorType":"validation","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Python/PipShowResult.cs","lineNumber":69,"sourceCode":"            var split = line.Split(':', 2);\n            if (split.Length != 2)\n                continue;\n\n            var key = split[0].Trim();\n            var value = split[1].Trim();\n\n            if (key == \"Name\" && linesDict.ContainsKey(\"Name\"))\n            {\n                // We've hit a new package, so stop parsing\n                break;\n            }\n\n            linesDict.TryAdd(key, value);\n        }\n\n        if (!linesDict.TryGetValue(\"Name\", out var name))\n        {\n            throw new FormatException(\"The 'Name' key was not found in the pip show output.\");\n        }\n\n        if (!linesDict.TryGetValue(\"Version\", out var version))\n        {\n            throw new FormatException(\"The 'Version' key was not found in the pip show output.\");\n        }\n\n        return new PipShowResult\n        {\n            Name = name,\n            Version = version,\n            Summary = linesDict.GetValueOrDefault(\"Summary\"),\n            HomePage = linesDict.GetValueOrDefault(\"Home-page\"),\n            Author = linesDict.GetValueOrDefault(\"Author\"),\n            AuthorEmail = linesDict.GetValueOrDefault(\"Author-email\"),\n            License = licenseText,\n            Location = linesDict.GetValueOrDefault(\"Location\"),\n            Requires = linesDict","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Python/PipShowResult.cs#L51-L87","documentation":"PipShowResult.Parse converts 'pip show' text output into a structured record by parsing 'Key: Value' lines. It requires at minimum a 'Name' key; if the output has no Name line, the output is not valid pip show output and a FormatException is thrown. This protects downstream consumers from a half-populated result.","triggerScenarios":"Passing the stdout of 'pip show <pkg>' to PipShowResult.Parse when the output lacks a 'Name:' line — typically because pip printed a warning/error message instead of package metadata (package not installed).","commonSituations":"Running pip show for a package that is not installed (pip prints 'WARNING: Package(s) not found'), parsing stderr or combined output, pip output format changes or locale differences.","solutions":["Verify the package is installed ('pip show <name>' succeeded) before parsing the output","Check that the string passed to Parse is stdout of pip show, not stderr or warning text","Check the first parsed line — a WARNING or ERROR line means pip did not emit package data","Handle FormatException and fall back to checking 'pip list' or exit codes"],"exampleFix":"// before\nvar result = PipShowResult.Parse(processResult.StandardOutput); // may be a WARNING line\n// after\nif (!processResult.ExitCodeIsZero || !processResult.StandardOutput.StartsWith(\"Name:\"))\n    throw new InvalidOperationException(\"Package not installed\");\nvar result = PipShowResult.Parse(processResult.StandardOutput);","handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrWhiteSpace(output) || !output.Contains(\"Name:\"))\n    throw new InvalidOperationException(\"Not valid pip show output (package likely not installed)\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var result = PipShowResult.Parse(output);\n}\ncatch (FormatException ex)\n{\n    logger.LogWarning(ex, \"pip show output missing Name key; package may not be installed\");\n    return null;\n}","preventionTips":["Check the pip process exit code before parsing stdout","Never parse stderr or combined output as pip show data","Treat WARNING/ERROR first lines as a signal not to parse"],"tags":["pip","parsing","format"],"backgroundTag":"unexpected-response-shape","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}