{"record":{"id":"65f689efdc0184ff","repo":"LykosAI/StabilityMatrix","slug":"invalid-package-specifier-value","errorCode":null,"errorMessage":"Invalid package specifier: {value}","messagePattern":"Invalid package specifier: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Python/PipPackageSpecifier.cs","lineNumber":47,"sourceCode":"    }\n\n    public static bool TryParse(string value, [NotNullWhen(true)] out PipPackageSpecifier? packageSpecifier)\n    {\n        return TryParse(value, false, out packageSpecifier);\n    }\n\n    private static bool TryParse(\n        string value,\n        bool throwOnFailure,\n        [NotNullWhen(true)] out PipPackageSpecifier? packageSpecifier\n    )\n    {\n        var match = PackageSpecifierRegex().Match(value);\n        if (!match.Success)\n        {\n            if (throwOnFailure)\n            {\n                throw new ArgumentException($\"Invalid package specifier: {value}\");\n            }\n\n            packageSpecifier = null;\n            return false;\n        }\n\n        packageSpecifier = new PipPackageSpecifier\n        {\n            Name = match.Groups[\"package_name\"].Value,\n            Constraint = match.Groups[\"version_constraint\"].Value,\n            Version = match.Groups[\"version\"].Value\n        };\n\n        return true;\n    }\n\n    /// <inheritdoc />\n    public override string ToString()","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Python/PipPackageSpecifier.cs#L29-L65","documentation":"PipPackageSpecifier.TryParse validates a pip package specifier (e.g. 'numpy==1.26.0', 'torch>=2.0') against a regex. When the string does not match the expected specifier grammar, it either returns false or throws ArgumentException with throwOnFailure=true. This guards callers from passing malformed package names into pip operations.","triggerScenarios":"Calling TryParse(value, ...) or the throwing overload with a string that fails PackageSpecifierRegex(), e.g. empty string, whitespace, illegal characters like 'numpy 1.0', or a bare '==' without a version.","commonSituations":"User-typed package names from a UI or config file containing typos, spaces, or extra characters; package strings copied with stray quotes; localized or URL-encoded inputs.","solutions":["Fix the package specifier string to a valid pip format like 'name', 'name==1.2.3', or 'name>=1.0,<2'","Trim whitespace and remove stray quotes or characters before parsing","Use the non-throwing TryParse and handle the false return instead of the throwing overload","Log the offending value to identify the source of the malformed input"],"exampleFix":"// before\nvar spec = PipPackageSpecifier.Parse(\"torch >=2, <2.4 !!\");\n// after\nvar spec = PipPackageSpecifier.Parse(\"torch>=2.0,<2.4\");","handlingStrategy":"validation","validationCode":"var isValid = !string.IsNullOrWhiteSpace(value) && System.Text.RegularExpressions.Regex.IsMatch(value, \"^[A-Za-z0-9_.-]+(==|>=|<=|>|<|~=)?[A-Za-z0-9_.!*]*$\");\nif (!isValid) throw new ArgumentException($\"Invalid pip package specifier: {value}\");","typeGuard":"bool IsValidPipSpecifier(string? value) =>\n    !string.IsNullOrWhiteSpace(value) && PipPackageSpecifier.TryParse(value, out _);","tryCatchPattern":"try\n{\n    var spec = PipPackageSpecifier.Parse(value);\n}\ncatch (ArgumentException ex)\n{\n    logger.LogWarning(ex, \"Bad package specifier: {Value}\", value);\n    // surface a validation message to the user\n}","preventionTips":["Validate user-entered package strings against the pip specifier grammar before use","Trim and sanitize inputs from UI/config sources","Prefer non-throwing TryParse when input origin is untrusted"],"tags":["pip","validation","argument"],"backgroundTag":"invalid-argument-format","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}