{"record":{"id":"b7774f7b1d99c3a3","repo":"microsoft/aspire","slug":"must-be-in-the-range-min-minmessage-max-maxmessage-guard","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.StackExchangeRedis/Shared/Guard.cs","lineNumber":229,"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":211,"sourceCodeEnd":234,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs#L211-L234","documentation":"Guard.Range (private helper behind the in-range checks) validates that a value lies within [min, max] and throws ArgumentOutOfRangeException with 'Must be in the range: [{min}{minMessage}, {max}{maxMessage}]'. The optional min/max messages annotate whether bounds are exclusive (e.g. '(0', '0)').","triggerScenarios":"Calling any Guard in-range check with a value outside the specified min/max bounds.","commonSituations":"Config values outside supported bounds (timeout too large, percentage > 100); off-by-one when passing an exclusive bound; unbounded counters growing past a limit.","solutions":["Read the range from the message and clamp/normalize the value into it before the call.","Validate the value at configuration-load time.","Fix arithmetic that pushed the value out of range.","If the caller's range expectation is wrong, adjust the min/max arguments at the check site."],"exampleFix":"// before\nGuard.ThrowIfNotInRange(percent, 0, 100); // percent == 150\n// after\npercent = Math.Clamp(percent, 0, 100);\nGuard.ThrowIfNotInRange(percent, 0, 100);","handlingStrategy":"validation","validationCode":"if (value < min || value > max) throw new ArgumentOutOfRangeException(nameof(value), value, $\"must be in [{min},{max}]\");","typeGuard":null,"tryCatchPattern":"catch (ArgumentOutOfRangeException ex) { /* clamp ActualValue into the stated range */ }","preventionTips":["Use Math.Clamp on user/config values.","Validate ranges at config-load time.","Note whether bounds are exclusive per the min/max messages."],"tags":["argument-validation","range","argument-out-of-range"],"backgroundTag":"value-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"}