Tyrrrz/DiscordChatExporter · error · FormatException

Invalid partition limit '{value}'.

Error message

Invalid partition limit '{value}'.

What it means

Thrown as FormatException by PartitionLimit.Parse when TryParse cannot interpret the input as either a file-size expression (e.g. '10mb') or an integer message count. Partitioning splits output into multiple files based on either accumulated byte size or message count; a value matching neither format is rejected. Typically surfaced via CLI binding of the --partition argument.

Source

Thrown at DiscordChatExporter.Core/Exporting/Partitioning/PartitionLimit.cs:65

        return (long)(number * magnitude);
    }

    public static PartitionLimit? TryParse(string value, IFormatProvider? formatProvider = null)
    {
        var fileSizeLimit = TryParseFileSizeBytes(value, formatProvider);
        if (fileSizeLimit is not null)
            return new FileSizePartitionLimit(fileSizeLimit.Value);

        if (int.TryParse(value, NumberStyles.Integer, formatProvider, out var messageCountLimit))
            return new MessageCountPartitionLimit(messageCountLimit);

        return null;
    }

    public static PartitionLimit Parse(string value, IFormatProvider? formatProvider = null) =>
        TryParse(value, formatProvider)
        ?? throw new FormatException($"Invalid partition limit '{value}'.");
}

View on GitHub (pinned to f6865c8216)

Solutions

  1. Use a file-size form recognized by the parser: a number followed by a unit, e.g. '10mb', '500kb', '1gb'.
  2. Or use a plain integer to partition by message count, e.g. '1000'.
  3. Remove whitespace and avoid thousands separators.
  4. Check TryParseFileSizeBytes' accepted unit tokens if unsure which suffixes are valid.

Example fix

// before
dotnet run -- exportchat -c <id> -t <token> --partition "1.5 MB"
// after
dotnet run -- exportchat -c <id> -t <token> --partition 10mb
Defensive patterns

Strategy: type-guard

Validate before calling

if (PartitionLimit.TryParse(rawPartition, null) is null)
    throw new ArgumentException($"'{rawPartition}' is not a valid partition limit (use '10mb' or '1000').");

Type guard

static PartitionLimit? TryPartition(string? s) =>
    string.IsNullOrWhiteSpace(s) ? null : PartitionLimit.TryParse(s, CultureInfo.InvariantCulture);

Try / catch

try { var limit = PartitionLimit.Parse(rawPartition); }
catch (FormatException) { logger.LogWarning("Bad partition '{Raw}'; falling back to no partitioning", rawPartition); limit = null; }

Prevention

When it happens

Trigger: PartitionLimit.Parse is called with a value that fails TryParseFileSizeBytes AND int.TryParse (PartitionLimit.cs:65). Common at the --partition option when binding CLI args.

Common situations: Passing a bare unit without a number ('mb'), a number without a recognized unit ('100x'), a decimal ('1.5mb'), or a typo ('1mbb'); using uppercase or unusual units the size parser does not accept; passing an expression like '100 messages'.

Related errors


AI-assisted analysis of Tyrrrz/DiscordChatExporter@f6865c8216 (2026-08-13). Data as JSON: /api/errors/a2ff647803255223. Report an issue: GitHub.