{"record":{"id":"2a25d11e196c527d","repo":"git-ecosystem/git-credential-manager","slug":"argument-must-be-greater-than-or-equal-to-lower","errorCode":null,"errorMessage":"Argument must be greater than or equal to {lower}.","messagePattern":"Argument must be greater than or equal to (.+?)\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Core/EnsureArgument.cs","lineNumber":81,"sourceCode":"            if (arg > 0)\n            {\n                throw new ArgumentOutOfRangeException(name, \"Argument must be negative or zero (non-positive).\");\n            }\n        }\n\n        public static void Negative(int arg, string name)\n        {\n            if (arg >= 0)\n            {\n                throw new ArgumentOutOfRangeException(name, \"Argument must be negative.\");\n            }\n        }\n\n        public static void InRange(int arg, string name, int lower, int upper, bool lowerInclusive = true, bool upperInclusive = true)\n        {\n            if (lowerInclusive && arg < lower)\n            {\n                throw new ArgumentOutOfRangeException(name, $\"Argument must be greater than or equal to {lower}.\");\n            }\n\n            if (!lowerInclusive && arg <= lower)\n            {\n                throw new ArgumentOutOfRangeException(name, $\"Argument must be strictly greater than {lower}.\");\n            }\n\n            if (upperInclusive && arg > upper)\n            {\n                throw new ArgumentOutOfRangeException(name, $\"Argument must be less than or equal to {upper}.\");\n            }\n\n            if (!upperInclusive && arg >= upper)\n            {\n                throw new ArgumentOutOfRangeException(name, $\"Argument must be strictly less than {upper}.\");\n            }\n        }\n    }","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/EnsureArgument.cs#L63-L99","documentation":"This ArgumentOutOfRangeException is thrown by EnsureArgument.InRange when the argument is below the lower bound while lowerInclusive is true. The value must satisfy arg >= lower. The interpolated message includes the actual lower bound, and the parameter name is attached to the exception.","triggerScenarios":"Calling EnsureArgument.InRange(arg, name, lower, upper) (default lowerInclusive: true) with arg < lower, e.g., a negative index into an array whose lower bound is 0, or a config value below the allowed minimum.","commonSituations":"Off-by-one errors where an exclusive bound was computed as inclusive; config values below a documented minimum; zero-based index calculations returning -1 for not-found.","solutions":["Check the value against the expected lower bound before the call and clamp or correct it","Fix the computation that yields a below-range value (e.g., handle a -1 not-found sentinel before indexing)","Correct the config/env value to be within the documented minimum","Verify you passed the bounds in the right order (lower, upper) - swapped bounds cause confusing failures"],"exampleFix":"// before\nEnsureArgument.InRange(index, nameof(index), 0, list.Count - 1); // index == -1\n// after\nif (index >= 0)\n    EnsureArgument.InRange(index, nameof(index), 0, list.Count - 1);","handlingStrategy":"validation","validationCode":"if (value < lower) throw new InvalidOperationException($\"{name} must be >= {lower}, was {value}\");\n// or: value = Math.Max(lower, value);","typeGuard":"static bool IsInRange(int v, int lower, int upper) => v >= lower && v <= upper;","tryCatchPattern":"try { EnsureArgument.InRange(index, nameof(index), 0, list.Count - 1); }\ncatch (ArgumentOutOfRangeException ex)\n{\n    logger.LogWarning(\"{Param}={Value} out of range; skipping item\", ex.ParamName, index);\n    return null; // fallback\n}","preventionTips":["Handle -1 not-found sentinels before range-checked indexing","Use length - 1 for inclusive zero-based upper bounds","Validate config minimums at startup","Double-check argument order (lower, upper) at call sites"],"tags":["argument-validation","range-check","bounds"],"backgroundTag":"value-out-of-range","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}