{"record":{"id":"23ba897bebd7d241","repo":"jstedfast/MailKit","slug":"the-filter-name-cannot-be-empty","errorCode":null,"errorMessage":"The filter name cannot be empty.","messagePattern":"The filter name cannot be empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Search/FilterSearchQuery.cs","lineNumber":58,"sourceCode":"\t\t/// Initializes a new instance of the <see cref=\"T:MailKit.Search.FilterSearchQuery\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// A search query that references a predefined filter.\n\t\t/// </remarks>\n\t\t/// <param name=\"name\">The name of the filter.</param>\n\t\t/// <exception cref=\"System.ArgumentNullException\">\n\t\t/// <paramref name=\"name\"/> is <see langword=\"null\" />.\n\t\t/// </exception>\n\t\t/// <exception cref=\"System.ArgumentException\">\n\t\t/// <paramref name=\"name\"/> is empty.\n\t\t/// </exception>\n\t\tpublic FilterSearchQuery (string name) : base (SearchTerm.Filter)\n\t\t{\n\t\t\tif (name == null)\n\t\t\t\tthrow new ArgumentNullException (nameof (name));\n\n\t\t\tif (name.Length == 0)\n\t\t\t\tthrow new ArgumentException (\"The filter name cannot be empty.\", nameof (name));\n\n\t\t\tName = name;\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Initializes a new instance of the <see cref=\"T:MailKit.Search.FilterSearchQuery\"/> class.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// A search query that references a predefined filter.\n\t\t/// </remarks>\n\t\t/// <param name=\"filter\">The metadata tag representing the filter.</param>\n\t\t/// <exception cref=\"System.ArgumentException\">\n\t\t/// <paramref name=\"filter\"/> does not reference a valid filter.\n\t\t/// </exception>\n\t\tpublic FilterSearchQuery (MetadataTag filter) : base (SearchTerm.Filter)\n\t\t{\n\t\t\tif (filter.Id.StartsWith (\"/private/filters/values/\", StringComparison.Ordinal))\n\t\t\t\tName = filter.Id.Substring (\"/private/filters/values/\".Length);","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Search/FilterSearchQuery.cs#L40-L76","documentation":"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.","triggerScenarios":"Calling new FilterSearchQuery(\"\") or SearchQuery.Filter(\"\") — commonly when a config value or Trim()ed user input is empty.","commonSituations":"Empty filter-name fields in settings files; trimming removed whitespace leaving an empty string; defaults never filled in.","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)."],"exampleFix":"// before\nvar query = SearchQuery.Filter(filterName.Trim());\n// after\nvar name = filterName?.Trim();\nif (string.IsNullOrEmpty(name)) throw new InvalidOperationException(\"filter name is required\");\nvar query = SearchQuery.Filter(name);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(filterName)) throw new InvalidOperationException(\"filter name must be non-empty\");","typeGuard":"bool HasValidFilterName(string name) => !string.IsNullOrWhiteSpace(name);","tryCatchPattern":"try { var q = SearchQuery.Filter(name); } catch (ArgumentException ex) { /* report empty filter name */ }","preventionTips":["Trim and check user/config filter names before use","Require non-empty values in config validation","Reject blank form fields at input time"],"tags":["csharp","mailkit","imap","search-query","argument-validation"],"backgroundTag":"empty-required-field","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}