{"record":{"id":"88783f0f409f5bed","repo":"git-ecosystem/git-credential-manager","slug":"argument-must-be-positive","errorCode":null,"errorMessage":"Argument must be positive.","messagePattern":"Argument must be positive\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Core/EnsureArgument.cs","lineNumber":57,"sourceCode":"            if (!arg.IsAbsoluteUri)\n            {\n                throw new ArgumentException(\"Argument must be an absolute URI.\", name);\n            }\n        }\n\n        public static void PositiveOrZero(int arg, string name)\n        {\n            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        }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/EnsureArgument.cs#L39-L75","documentation":"This ArgumentOutOfRangeException is thrown by EnsureArgument.Positive when an int argument is zero or negative. The parameter must be strictly greater than zero (> 0), e.g., a page size, batch size, or count. The parameter name is included in the exception.","triggerScenarios":"Calling EnsureArgument.Positive(arg, name) with arg <= 0, e.g., an uninitialized/default(int) == 0 value, an empty collection's count, or a config value of \"0\" or negative.","commonSituations":"Forgetting to initialize a field so it stays at the default 0; dividing work by a batch size that was configured as 0; taking .Count of an empty list; config placeholder \"0\" never replaced.","solutions":["Ensure the value is >= 1 before the call, e.g., Math.Max(1, value) or a proper default","Check initialization order - the value may not have been set before first use","Fix the config/source producing 0 or a negative value","If 0 is valid \"unset\", switch to int? and validate only when set"],"exampleFix":"// before\nEnsureArgument.Positive(batchSize, nameof(batchSize)); // batchSize defaults to 0\n// after\nint batchSize = config.BatchSize > 0 ? config.BatchSize : DefaultBatchSize;\nEnsureArgument.Positive(batchSize, nameof(batchSize));","handlingStrategy":"validation","validationCode":"if (value <= 0) throw new InvalidOperationException($\"{name} must be > 0, was {value}\");\n// or default: value = value > 0 ? value : DefaultValue;","typeGuard":"static bool IsPositive(int v) => v > 0;","tryCatchPattern":"try { EnsureArgument.Positive(batchSize, nameof(batchSize)); }\ncatch (ArgumentOutOfRangeException ex)\n{\n    logger.LogError(\"{Param}={Value}; must be strictly positive\", ex.ParamName, batchSize);\n    batchSize = DefaultBatchSize;\n}","preventionTips":["Give non-zero defaults to fields used as counts/sizes before first use","Never pass list.Count of an possibly-empty list where > 0 is required","Validate batch/page-size config at startup (must be >= 1)","Use Math.Max(1, value) as a defensive normalization"],"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"}