{"record":{"id":"3f8465dc949d15b4","repo":"abpframework/abp","slug":"invalid-background-job-name-filter-mode-mode","errorCode":null,"errorMessage":"Invalid background job name filter mode: {mode}","messagePattern":"Invalid background job name filter mode: (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobNameFilter.cs","lineNumber":27,"sourceCode":"/// A worker is exactly one of: no filter (<see cref=\"None\"/>), include-only (a dedicated worker) or\n/// exclude-only (the default worker in a multi-worker setup) — the two can never be combined.\n/// </summary>\npublic class BackgroundJobNameFilter\n{\n    /// <summary>\n    /// A filter that matches every job name.\n    /// </summary>\n    public static BackgroundJobNameFilter None { get; } = new(BackgroundJobNameFilterMode.None);\n\n    public BackgroundJobNameFilterMode Mode { get; }\n\n    public IReadOnlyList<string> JobNames { get; }\n\n    public BackgroundJobNameFilter(BackgroundJobNameFilterMode mode, IReadOnlyList<string>? jobNames = null)\n    {\n        if (!Enum.IsDefined(typeof(BackgroundJobNameFilterMode), mode))\n        {\n            throw new ArgumentException($\"Invalid background job name filter mode: {mode}\", nameof(mode));\n        }\n\n        var names = jobNames?.Where(x => !x.IsNullOrWhiteSpace()).Distinct(StringComparer.Ordinal).ToList() ?? new List<string>();\n\n        if (mode == BackgroundJobNameFilterMode.None && names.Count > 0)\n        {\n            throw new ArgumentException(\"Job names must be empty when the filter mode is None.\", nameof(jobNames));\n        }\n\n        if (mode != BackgroundJobNameFilterMode.None && names.Count == 0)\n        {\n            throw new ArgumentException(\"Job names cannot be empty when the filter mode is Include or Exclude.\", nameof(jobNames));\n        }\n\n        Mode = mode;\n        JobNames = names.AsReadOnly();\n    }\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobNameFilter.cs#L9-L45","documentation":"Thrown by the BackgroundJobNameFilter constructor when the mode argument is not a defined BackgroundJobNameFilterMode enum value (checked via Enum.IsDefined). This catches corrupted/invalid enum values cast from integers or default uninitialized mode fields.","triggerScenarios":"Constructing new BackgroundJobNameFilter((BackgroundJobNameFilterMode)999, ...) with an out-of-range int cast to the enum, or passing an uninitialized (defaulted) mode that isn't a valid member.","commonSituations":"Casting an arbitrary integer to the enum; deserializing a mode value that doesn't match any defined member; uninitialized struct field defaulting to an invalid value; future enum member removed but caller still sends the old integer.","solutions":["Pass only defined BackgroundJobNameFilterMode values (None, Include, Exclude).","Validate the enum value with Enum.IsDefined before constructing the filter.","Use the static factories Include(...) / Exclude(...) / None instead of the constructor to avoid bad casts.","If deserializing, constrain/validate accepted values at the boundary."],"exampleFix":"// before\nvar f = new BackgroundJobNameFilter((BackgroundJobNameFilterMode)42, names); // throws\n// after\nvar f = BackgroundJobNameFilter.Include(names);","handlingStrategy":"type-guard","validationCode":"if (!Enum.IsDefined(typeof(BackgroundJobNameFilterMode), mode))\n{\n    /* reject/normalize before constructing BackgroundJobNameFilter */\n}","typeGuard":"static bool IsValidMode(BackgroundJobNameFilterMode m) => Enum.IsDefined(typeof(BackgroundJobNameFilterMode), m);","tryCatchPattern":"try { var f = new BackgroundJobNameFilter(mode, names); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid background job name filter mode\"))\n{ /* coerce to a valid mode or reject input */ }","preventionTips":["Use the static factories Include/Exclude/None instead of the constructor.","Validate deserialized enum values with Enum.IsDefined at the boundary.","Never cast arbitrary integers to the enum.","Keep enum values in sync across API contracts."],"tags":["background-jobs","abp","validation","enum"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}