{"record":{"id":"5180e07af9c632ec","repo":"microsoft/aspire","slug":"must-not-be-zero","errorCode":null,"errorMessage":"Must not be zero","messagePattern":"Must not be zero","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs","lineNumber":116,"sourceCode":"            {\n                throw new ArgumentException(\"Must not be null or whitespace\", paramName);\n            }\n        }\n#pragma warning restore CS8777 // Parameter must have a non-null value when exiting.\n\n        /// <summary>\n        /// Throw an exception if the value is zero.\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 ThrowIfZero(int value, string message = \"Must not be zero\", [CallerArgumentExpression(\"value\")] string? paramName = null)\n        {\n            if (value == 0)\n            {\n                throw new ArgumentException(message, paramName);\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(\"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":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs#L98-L134","documentation":"Thrown by Guard.ThrowIfZero in the vendored ConfluentKafka instrumentation's Guard helper when an int parameter equals zero, which the API treats as invalid. It throws ArgumentException with the parameter name and a default message of \"Must not be zero\". Typically used where zero is an ambiguous or meaningless value (e.g. an ID or count that must be positive).","triggerScenarios":"Passing 0 for a guarded int argument such as an identifier, count, or quantity where a non-zero (usually positive) value is required.","commonSituations":"Uninitialized int fields defaulting to 0; ID lookups that returned default(int) when no record was found; counters or limits computed as zero from empty data.","solutions":["Find the argument named in the exception and ensure a valid non-zero value is computed before the call.","Treat a zero value as an early error in your own code: check and skip or throw a domain-specific exception.","Investigate why the value was default(int) - often a failed lookup or uninitialized field rather than a legitimate 0."],"exampleFix":"// before\nint id = dict.GetValueOrDefault(\"id\"); // 0 when missing\nRegisterId(id);\n\n// after\nint id = dict.GetValueOrDefault(\"id\");\nif (id == 0)\n{\n    throw new InvalidOperationException(\"id was not provided\");\n}\nRegisterId(id);","handlingStrategy":"validation","validationCode":"if (value == 0)\n{\n    throw new ArgumentException(\"Must not be zero\", nameof(value));\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    instrumented.SetCount(count);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"count\")\n{\n    logger.LogError(ex, \"count must be non-zero\");\n}","preventionTips":["Treat default(int) as suspicious when it represents an ID or count","Use nullable ints instead of 0 sentinels for missing values","Check lookup results before using the resulting numeric value"],"tags":["argument-value","zero","validation","opentelemetry","kafka"],"backgroundTag":"invalid-argument-value","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"}