{"record":{"id":"02a0d3919a060209","repo":"microsoft/aspire","slug":"must-not-be-negative","errorCode":null,"errorMessage":"Must not be negative","messagePattern":"Must not be negative","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs","lineNumber":147,"sourceCode":"            {\n                throw new ArgumentException(message, paramName);\n            }\n#endif\n        }\n\n        /// <summary>\n        /// Throw an exception if the value is negative.\n        /// </summary>\n        /// <param name=\"value\">The value to check.</param>\n        /// <param name=\"message\">The message to use in the thrown exception.</param>\n        /// <param name=\"paramName\">The parameter name to use in the thrown exception.</param>\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static void ThrowIfNegative(int value, string message = \"Must not be negative\", [CallerArgumentExpression(nameof(value))] string? paramName = null)\n        {\n            if (value < 0)\n            {\n                throw new ArgumentOutOfRangeException(paramName, message);\n            }\n        }\n\n        /// <summary>\n        /// Throw an exception if the value is not considered a valid timeout.\n        /// </summary>\n        /// <param name=\"value\">The value to check.</param>\n        /// <param name=\"paramName\">The parameter name to use in the thrown exception.</param>\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static void ThrowIfInvalidTimeout(int value, [CallerArgumentExpression(nameof(value))] string? paramName = null)\n        {\n            ThrowIfOutOfRange(value, paramName, min: Timeout.Infinite, message: $\"Must be non-negative or '{nameof(Timeout)}.{nameof(Timeout.Infinite)}'\");\n        }\n\n        /// <summary>\n        /// Throw an exception if the value is not within the given range.\n        /// </summary>","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs#L129-L165","documentation":"Guard.ThrowIfNegative validates that an int argument is not negative, throwing ArgumentOutOfRangeException with 'Must not be negative'. The StackExchangeRedis instrumentation uses it to reject negative counts, timeouts, or sizes early with a clear parameter name captured from the caller's expression via CallerArgumentExpression.","triggerScenarios":"Calling Guard.ThrowIfNegative(value) or APIs that use it, with a negative int value.","commonSituations":"Computing a delta/remaining count that went negative; misconfigured timeout or batch size; integer overflow wrapping to negative.","solutions":["Fix the value so it is >= 0 before the call.","Clamp with Math.Max(0, value) if negative is expected from arithmetic.","Validate configuration inputs at startup so negatives never reach the call.","Check upstream arithmetic (subtraction/overflow) that produced the negative number."],"exampleFix":"// before\nGuard.ThrowIfNegative(maxRetries); // computed value was -1\n// after\nmaxRetries = Math.Max(0, maxRetries);\nGuard.ThrowIfNegative(maxRetries);","handlingStrategy":"validation","validationCode":"if (value < 0) throw new ArgumentOutOfRangeException(nameof(value), value, \"must be >= 0\");","typeGuard":null,"tryCatchPattern":"catch (ArgumentOutOfRangeException ex) when (ex.ParamName == paramName) { value = Math.Max(0, value); }","preventionTips":["Clamp computed values with Math.Max(0, x).","Watch for subtraction/overflow producing negatives.","Validate configuration ranges at load time."],"tags":["argument-validation","guard","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}