Tyrrrz/DiscordChatExporter · error · FormatException

Invalid snowflake '{value}'.

Error message

Invalid snowflake '{value}'.

What it means

Thrown as FormatException by Snowflake.Parse when TryParse cannot interpret the input as either an unsigned 64-bit integer or a parseable DateTimeOffset. Snowflakes are Discord's numeric IDs but the parser also accepts ISO/date strings for convenience; anything else is invalid. This is a parsing error typically surfaced by CLI argument binding.

Source

Thrown at DiscordChatExporter.Core/Discord/Snowflake.cs:43

    public static Snowflake? TryParse(string? value, IFormatProvider? formatProvider = null)
    {
        if (string.IsNullOrWhiteSpace(value))
            return null;

        // As number
        if (ulong.TryParse(value, NumberStyles.None, formatProvider, out var number))
            return new Snowflake(number);

        // As date
        if (DateTimeOffset.TryParse(value, formatProvider, DateTimeStyles.None, out var instant))
            return FromDate(instant);

        return null;
    }

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

    public static Snowflake Parse(string value) => Parse(value, null);
}

public partial record struct Snowflake : IComparable<Snowflake>, IComparable
{
    public int CompareTo(Snowflake other) => Value.CompareTo(other.Value);

    public int CompareTo(object? obj)
    {
        if (obj is not Snowflake other)
            throw new ArgumentException($"Object must be of type {nameof(Snowflake)}.");

        return Value.CompareTo(other.Value);
    }

    public static bool operator >(Snowflake left, Snowflake right) => left.CompareTo(right) > 0;

View on GitHub (pinned to f6865c8216)

Solutions

  1. Supply the raw numeric snowflake (e.g. `1234567890123456789`) with no formatting.
  2. For date inputs, use an unambiguous ISO-8601 string (e.g. `2024-01-31T00:00:00Z`).
  3. Strip mention markup (`<#`, `<@`, `>`) and URL fragments before parsing.
  4. If parsing with a specific culture, pass an IFormatProvider whose date formats accept your string.

Example fix

// before
var id = Snowflake.Parse("<#1234567890123456789>");
// after
var id = Snowflake.Parse("1234567890123456789");
Defensive patterns

Strategy: type-guard

Validate before calling

bool IsLikelySnowflake(string s) =>
    ulong.TryParse(s, NumberStyles.None, CultureInfo.InvariantCulture, out _);
if (!IsLikelySnowflake(input)) throw new ArgumentException($"'{input}' is not a numeric snowflake.");

Type guard

static Snowflake? TryParseSnowflake(string? raw) =>
    string.IsNullOrWhiteSpace(raw) ? null : Snowflake.TryParse(raw, CultureInfo.InvariantCulture);

Try / catch

try { var id = Snowflake.Parse(raw, CultureInfo.InvariantCulture); }
catch (FormatException) { logger.LogWarning("Ignoring malformed id '{Raw}'", raw); return; }

Prevention

When it happens

Trigger: Snowflake.Parse is called (e.g. when binding a -c/--channel, -g/--guild, or date argument) with a value that is neither a plain numeric string nor a culture-parseable date. TryParse returns null at Snowflake.cs:36 and Parse throws.

Common situations: Pasting a channel URL fragment instead of the bare ID (e.g. '/channels/123/456'); ID with commas/thousands separators; locale-specific date string that does not parse with the configured culture; leading '<#' or trailing '>' from a copied mention; negative or decimal number.

Related errors


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