jstedfast/MailKit · error · ArgumentException
The filter name cannot be empty.
Error message
The filter name cannot be empty.
What it means
FilterSearchQuery throws ArgumentException when the filter name is the empty string. An empty name cannot match any server-side filter metadata tag, so the library rejects it eagerly rather than producing a query that always fails.
Solutions
- Supply the real filter name from the IMAP server (must be non-empty).
- Validate with string.IsNullOrWhiteSpace before constructing; surface a config error instead.
- Fix whatever produced the empty value (config key missing, blank form field).
Example fix
// before
var query = SearchQuery.Filter(filterName.Trim());
// after
var name = filterName?.Trim();
if (string.IsNullOrEmpty(name)) throw new InvalidOperationException("filter name is required");
var query = SearchQuery.Filter(name); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(filterName)) throw new InvalidOperationException("filter name must be non-empty"); Type guard
bool HasValidFilterName(string name) => !string.IsNullOrWhiteSpace(name);
Try / catch
try { var q = SearchQuery.Filter(name); } catch (ArgumentException ex) { /* report empty filter name */ } Prevention
- Trim and check user/config filter names before use
- Require non-empty values in config validation
- Reject blank form fields at input time
When it happens
Trigger: Calling new FilterSearchQuery("") or SearchQuery.Filter("") — commonly when a config value or Trim()ed user input is empty.
Common situations: Empty filter-name fields in settings files; trimming removed whitespace leaving an empty string; defaults never filled in.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- The uid is invalid.
- Only the "value", "value.priv", and "value.shared"…
- Metadata tag does not reference a valid filter.
- ArgumentOutOfRangeException
- ArgumentNullException
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/23ba897bebd7d241.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Search/FilterSearchQuery.cs:58
/// Initializes a new instance of the <see cref="T:MailKit.Search.FilterSearchQuery"/> class.
/// </summary>
/// <remarks>
/// A search query that references a predefined filter.
/// </remarks>
/// <param name="name">The name of the filter.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="name"/> is <see langword="null" />.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="name"/> is empty.
/// </exception>
public FilterSearchQuery (string name) : base (SearchTerm.Filter)
{
if (name == null)
throw new ArgumentNullException (nameof (name));
if (name.Length == 0)
throw new ArgumentException ("The filter name cannot be empty.", nameof (name));
Name = name;
}
/// <summary>
/// Initializes a new instance of the <see cref="T:MailKit.Search.FilterSearchQuery"/> class.
/// </summary>
/// <remarks>
/// A search query that references a predefined filter.
/// </remarks>
/// <param name="filter">The metadata tag representing the filter.</param>
/// <exception cref="System.ArgumentException">
/// <paramref name="filter"/> does not reference a valid filter.
/// </exception>
public FilterSearchQuery (MetadataTag filter) : base (SearchTerm.Filter)
{
if (filter.Id.StartsWith ("/private/filters/values/", StringComparison.Ordinal))
Name = filter.Id.Substring ("/private/filters/values/".Length);View on GitHub (pinned to 9d3859a785)