{"record":{"id":"35e319335fd75b8d","repo":"git-ecosystem/git-credential-manager","slug":"argument-must-be-negative-or-zero-non-positive","errorCode":null,"errorMessage":"Argument must be negative or zero (non-positive).","messagePattern":"Argument must be negative or zero \\(non-positive\\)\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Core/EnsureArgument.cs","lineNumber":65,"sourceCode":"            if (arg < 0)\n            {\n                throw new ArgumentOutOfRangeException(name, \"Argument must be positive or zero (non-negative).\");\n            }\n        }\n\n        public static void Positive(int arg, string name)\n        {\n            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","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/EnsureArgument.cs#L47-L83","documentation":"This ArgumentOutOfRangeException is thrown by EnsureArgument.NegativeOrZero when an int argument is positive. The parameter is expected to be non-positive (<= 0), which is uncommon and typically used for offsets, decrements, or temperature-like scales where only zero or negative values are meaningful.","triggerScenarios":"Calling EnsureArgument.NegativeOrZero(arg, name) with arg > 0, e.g., sign-flipped math, subtracting in the wrong direction, or passing a magnitude where a negative offset was required.","commonSituations":"Sign errors when computing offsets or adjustments; passing a positive step to an API expecting a backward decrement; a config value that should be negative (e.g., timezone offset west) entered as positive.","solutions":["Verify the sign convention of the API you are calling and negate the value if needed","Fix the computation producing a positive value (e.g., use Math.Min(0, value) or correct operand order)","Check config sign conventions and document them","Review recent changes that may have flipped a subtraction"],"exampleFix":"// before\nEnsureArgument.NegativeOrZero(offset, nameof(offset)); // offset = 5\n// after\nvar adjustedOffset = -Math.Abs(offset);\nEnsureArgument.NegativeOrZero(adjustedOffset, nameof(adjustedOffset));","handlingStrategy":"validation","validationCode":"if (value > 0) value = -value; // enforce sign convention\nEnsureArgument.NegativeOrZero(value, nameof(value));","typeGuard":"static bool IsNonPositive(int v) => v <= 0;","tryCatchPattern":"try { EnsureArgument.NegativeOrZero(offset, nameof(offset)); }\ncatch (ArgumentOutOfRangeException ex)\n{\n    throw new InvalidOperationException($\"{ex.ParamName} must be <= 0, was {offset}; check sign convention\", ex);\n}","preventionTips":["Document sign conventions for offsets/deltas in API docs","Use Math.Min(0, x) to enforce non-positive results","Check subtraction operand order when computing negative-going values","Validate config signs (e.g., negative offsets) at startup"],"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"}