{"record":{"id":"f276025bdcddf6ac","repo":"git-ecosystem/git-credential-manager","slug":"argument-must-be-negative","errorCode":null,"errorMessage":"Argument must be negative.","messagePattern":"Argument must be negative\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Core/EnsureArgument.cs","lineNumber":73,"sourceCode":"            if (arg <= 0)\n            {\n                throw new ArgumentOutOfRangeException(name, \"Argument must be positive.\");\n            }\n        }\n\n        public static void NegativeOrZero(int arg, string name)\n        {\n            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}.\");","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/EnsureArgument.cs#L55-L91","documentation":"This ArgumentOutOfRangeException is thrown by EnsureArgument.Negative when an int argument is zero or positive. The parameter must be strictly negative (< 0), which is rare and usually indicates a sign-sensitive value such as a negative offset. The parameter name is included in the exception.","triggerScenarios":"Calling EnsureArgument.Negative(arg, name) with arg >= 0, e.g., passing 0 where a strictly negative value is demanded, or a sign error in offset/delta computation.","commonSituations":"Misunderstanding a strict-negative requirement and passing 0; flipped subtraction order; config values that should be negative entered positive.","solutions":["Ensure the value is < 0 (note: 0 also fails - use NegativeOrZero if zero is acceptable)","Negate the computed value if the sign convention was misapplied","Fix the upstream computation or config producing a non-negative value","Re-read the API documentation for the strict-negative requirement"],"exampleFix":"// before\nEnsureArgument.Negative(delta, nameof(delta)); // delta = 0\n// after\nif (delta >= 0)\n    delta = -1; // or handle zero as a distinct case\nEnsureArgument.Negative(delta, nameof(delta));","handlingStrategy":"validation","validationCode":"if (value >= 0) value = -1; // or handle explicitly\nEnsureArgument.Negative(value, nameof(value));","typeGuard":"static bool IsNegative(int v) => v < 0;","tryCatchPattern":"try { EnsureArgument.Negative(delta, nameof(delta)); }\ncatch (ArgumentOutOfRangeException ex)\n{\n    throw new InvalidOperationException($\"{ex.ParamName} must be strictly < 0 (zero not allowed), was {delta}\", ex);\n}","preventionTips":["Remember 0 fails strict-negative checks; use NegativeOrZero if zero is valid","Negate magnitudes deliberately with -Math.Abs(x) when a negative value is required","Verify sign conventions before calling sign-sensitive APIs","Check config files for values that should be negative"],"tags":["argument-validation","range-check","csharp"],"backgroundTag":"argument-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"}