{"record":{"id":"36ec40ef232ec851","repo":"microsoft/aspire","slug":"must-be-in-the-range-min-minmessage-max-maxmessage","errorCode":null,"errorMessage":"Must be in the range: [{min}{minMessage}, {max}{maxMessage}]","messagePattern":"Must be in the range: \\[(.+?)(.+?), (.+?)(.+?)\\]","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs","lineNumber":201,"sourceCode":"        }\n\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        private static void Range<T>(T value, string? paramName, T min, T max, string? minName, string? maxName, string? message)\n            where T : IComparable<T>\n        {\n            if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0)\n            {\n                var minMessage = minName != null ? $\": {minName}\" : string.Empty;\n                var maxMessage = maxName != null ? $\": {maxName}\" : string.Empty;\n                var exMessage = message ?? string.Format(\n                    CultureInfo.InvariantCulture,\n                    \"Must be in the range: [{0}{1}, {2}{3}]\",\n                    min,\n                    minMessage,\n                    max,\n                    maxMessage);\n                throw new ArgumentOutOfRangeException(paramName, value, exMessage);\n            }\n        }\n    }\n}\n","sourceCodeStart":183,"sourceCodeEnd":206,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs#L183-L206","documentation":"Thrown by Guard.ThrowIfOutOfRange (Range helper) in the vendored ConfluentKafka instrumentation's Guard when a numeric argument falls outside the inclusive/exclusive bounds passed by the caller. It throws ArgumentOutOfRangeException carrying the parameter name, the offending value, and a composed message describing the allowed range (bracket style indicates inclusivity). Typically guards timeouts, sizes, and quantities.","triggerScenarios":"Calling a guarded API with a value outside the documented range, e.g. a negative or zero timeout, a period longer than the allowed maximum, or a value that must be exclusive-bounded and exactly equals the boundary.","commonSituations":"Configuration values like sampling period, batch size, or timeout loaded as -1 or 0 from config; units mistakes (milliseconds vs seconds) pushing values past max; boundary values that violate exclusive bounds.","solutions":["Read the allowed range from the exception message and clamp or correct the argument to be within it.","Fix the configuration source (appsettings/env var) that supplied the out-of-range value.","Validate ranges at your own boundary with ArgumentOutOfRangeException.ThrowIfOutOfRange-style checks before calling."],"exampleFix":"// before\nvar timeout = TimeSpan.FromSeconds(config.GetValue(\"Timeout\", -1));\nSetTimeout(timeout);\n\n// after\nvar seconds = config.GetValue(\"Timeout\", 30);\nArgumentOutOfRangeException.ThrowIfLessThan(seconds, 1);\nSetTimeout(TimeSpan.FromSeconds(seconds));","handlingStrategy":"validation","validationCode":"if (value < min || value > max)\n{\n    throw new ArgumentOutOfRangeException(nameof(value), value, $\"Must be in the range [{min}, {max}]\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    instrumented.SetTimeout(timeout);\n}\ncatch (ArgumentOutOfRangeException ex)\n{\n    logger.LogError(ex, \"timeout {Value} outside allowed range: {Message}\", ex.ActualValue, ex.Message);\n}","preventionTips":["Clamp config-driven numeric values to documented ranges at startup","Watch for unit mistakes (ms vs seconds) when converting durations","Validate boundary values when bounds are exclusive"],"tags":["argument-out-of-range","validation","opentelemetry","kafka"],"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"}