louthy/language-ext · error · ArgumentException

s

Error message

s

What it means

StringM's ISpanParsable<SELF>.Parse checks the span length against System.String's maximum length (1,073,741,791 chars) and throws ArgumentException (with the parameter name "s" as the message) when exceeded, before converting via SELF.FromUnsafe.

Solutions

  1. Check s.Length <= 1073741791 before invoking any parse that funnels into StringM.Parse.
  2. Reject or stream-process oversized inputs upstream instead of converting them to strings.
  3. If parsing is genuinely needed, split the input into chunks within the limit.

Example fix

// before
var value = SELF.Parse(span, provider); // throws for giant spans

// after
if (span.Length > 1073741791) throw new ArgumentException("input too large to parse", nameof(span));
var value = SELF.Parse(span, provider);
Defensive patterns

Strategy: validation

Validate before calling

// before parsing
const int MaxStringLen = 1073741791;
if (s.Length > MaxStringLen) throw new ArgumentException("input exceeds max string length", nameof(s));

Type guard

static bool Parseable(ReadOnlySpan<char> s) => s.Length <= 1073741791;

Try / catch

try { var v = SELF.Parse(span, provider); }
catch (ArgumentException) { /* input exceeds System.String max length — reject input */ }

Prevention

When it happens

Trigger: Implicitly invoking Parse (via ISpanParsable/IParsable APIs like int.Parse-style parsing, span conversions, or parsing pipelines) with a ReadOnlySpan<char> longer than 1,073,741,791 characters.

Common situations: Parsing enormous in-memory text blobs or memory-mapped files as strings; upstream data-size limits missing so oversized spans reach Parse; angle of attack — pathological inputs in deserialization paths.

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 louthy/language-ext@2f0e362824 (2026-09-15). Data as JSON: /api/errors/3df9dbccd1fc7934. Report an issue: GitHub.

Appendix: source

Thrown at LanguageExt.Core/DataTypes/StringM/StringM.Trait.cs:72

    
    int IComparable<SELF>.CompareTo(SELF? rhs) =>
        rhs is null 
            ? 1 
            : SELF.Compare((SELF)this, rhs);

    static SELF IParsable<SELF>.Parse(string s, IFormatProvider? provider) => 
        SELF.FromUnsafe(s);

    static bool IParsable<SELF>.TryParse(string? s, IFormatProvider? provider, out SELF result)
    {
        result = SELF.FromUnsafe(s ?? "");
        return s != null;
    }

    static SELF ISpanParsable<SELF>.Parse(ReadOnlySpan<char> s, IFormatProvider? provider)
    {
        // magic number from System.String
        if (s.Length > 1073741791) throw new ArgumentException(nameof(s));
        return SELF.FromUnsafe(s.ToString());
    }

    static bool ISpanParsable<SELF>.TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out SELF result)
    {
        if (s.Length <= 1073741791) // magic number from System.String
        {
            result = SELF.FromUnsafe(s.ToString());
            return true;
        }
        result = default!;
        return false;
    }
}

View on GitHub (pinned to 2f0e362824)