LykosAI/StabilityMatrix · error · ArgumentException

Invalid or unsupported package specifier for uv

Error message

Invalid or unsupported package specifier for uv: {value}

What it means

UvPackageSpecifier.TryParse only accepts name, name+version specifiers and PEP 508-style extras/constraint forms it recognizes; on throwOnFailure=true it throws ArgumentException for anything else. It guards the uv-based pip alternative against specifiers it cannot map.

Solutions

  1. Use a standard PyPI specifier: name, name==version, name[extra]>=version.
  2. Install from URLs/paths/VCS via the regular pip pipeline instead of the uv path.
  3. Call the non-throwing TryParse overload to validate user input first.
  4. Check for typos (double '==', stray semicolons, markers) in the specifier.

Example fix

// before
UvPackageSpecifier.TryParse("git+https://github.com/x/y.git", out var spec, throwOnFailure: true);
// after
if (!UvPackageSpecifier.TryParse("torch>=2.1", out var spec, throwOnFailure: true)) { /* handled */ }
Defensive patterns

Strategy: validation

Validate before calling

bool IsSupportedSpecifier(string s) =>
    !s.StartsWith("git+") && !Uri.IsWellFormedUriString(s, UriKind.Absolute) &&
    !s.Contains(';') && System.Text.RegularExpressions.Regex.IsMatch(s, "^[A-Za-z0-9._-]+(\[.*\])?(.*)?$");

Type guard

static bool IsPlainRequirement(string s) {
    var name = System.Text.RegularExpressions.Regex.Match(s, "^[A-Za-z0-9._-]+");
    return name.Success && !s.StartsWith("git+") && !File.Exists(s) && !Uri.IsWellFormedUriString(s, UriKind.Absolute);
}

Try / catch

try { ok = UvPackageSpecifier.TryParse(spec, out var p, throwOnFailure: true); }
catch (ArgumentException ex) { Logger.Warn(ex, "unsupported uv specifier {Spec}", spec); ok = false; }

Prevention

When it happens

Trigger: Calling the TryParse overload with throwOnFailure:true and a specifier such as a local path, URL, VCS link (git+https://...), or an unsupported syntax the uv specifier parser doesn't model.

Common situations: Installing directly from git URLs or local wheel paths through the uv path; typo'd requirement strings; requirements-style lines with environment markers the parser rejects.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12). Data as JSON: /api/errors/368ebecf2cdfa2e6. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Core/Python/UvPackageSpecifier.cs:62

        // Enhancements could be made here to support git URLs, local paths, etc. if needed.
        var match = PackageSpecifierRegex().Match(value);
        if (!match.Success)
        {
            // Check if it's a URL or path-like specifier (basic check)
            // uv supports these directly. For simplicity, we'll treat them as a Name-only specifier for now.
            if (
                Uri.IsWellFormedUriString(value, UriKind.Absolute)
                || value.Contains(Path.DirectorySeparatorChar)
                || value.Contains(Path.AltDirectorySeparatorChar)
            )
            {
                packageSpecifier = new UvPackageSpecifier { Name = value };
                return true;
            }

            if (throwOnFailure)
            {
                throw new ArgumentException($"Invalid or unsupported package specifier for uv: {value}");
            }

            packageSpecifier = null;
            return false;
        }

        packageSpecifier = new UvPackageSpecifier
        {
            Name = match.Groups["package_name"].Value,
            Constraint = match.Groups["version_constraint"].Value, // Will be empty string if no constraint
            Version = match.Groups["version"].Value // Will be empty string if no version
        };

        // Ensure Constraint and Version are null if they were empty strings from regex.
        if (string.IsNullOrEmpty(packageSpecifier.Constraint))
            packageSpecifier.Constraint = null;
        if (string.IsNullOrEmpty(packageSpecifier.Version))
            packageSpecifier.Version = null;

View on GitHub (pinned to af93d6ef57)