{"record":{"id":"0996d49d91fd33cc","repo":"microsoft/aspire","slug":"must-not-be-null-or-empty","errorCode":null,"errorMessage":"Must not be null or empty","messagePattern":"Must not be null or empty","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs","lineNumber":82,"sourceCode":"            if (value is null)\n            {\n                throw new ArgumentNullException(paramName, \"Must not be null\");\n            }\n        }\n\n        /// <summary>\n        /// Throw an exception if the value is null or empty.\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 ThrowIfNullOrEmpty([NotNull] string? value, [CallerArgumentExpression(\"value\")] string? paramName = null)\n#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.\n        {\n            if (string.IsNullOrEmpty(value))\n            {\n                throw new ArgumentException(\"Must not be null or empty\", 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 null or whitespace.\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 ThrowIfNullOrWhitespace([NotNull] string? value, [CallerArgumentExpression(\"value\")] string? paramName = null)\n#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.\n        {\n            if (string.IsNullOrWhiteSpace(value))\n            {\n                throw new ArgumentException(\"Must not be null or whitespace\", paramName);\n            }","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs#L64-L100","documentation":"Thrown by Guard.ThrowIfNullOrEmpty in the vendored ConfluentKafka instrumentation's Guard helper when a required string parameter is null or the empty string. It wraps ArgumentException with the offending parameter name and asserts the value is non-null on exit. It guards required string configuration such as names, keys, or identifiers.","triggerScenarios":"Calling a guarded API with a required string argument set to null or \"\", e.g. an empty bootstrap servers string, empty operation/topic name, or unset configuration value passed straight through.","commonSituations":"Connection strings or bootstrap servers read from configuration that resolved to an empty string; missing environment variables whose defaults are empty; string fields initialized to \"\" instead of real values.","solutions":["Read paramName from the ArgumentException and supply a non-empty value for that argument before the call.","Validate string inputs with Guard.ThrowIfNullOrEmpty or ArgumentException.ThrowIfNullOrEmpty at your own boundary.","Trace back the string to its source (config/env var) and fix the empty value there."],"exampleFix":"// before\nvar bootstrap = configuration[\"Kafka:BootstrapServers\"]; // \"\"\nUseBootstrapServers(bootstrap);\n\n// after\nvar bootstrap = configuration[\"Kafka:BootstrapServers\"];\nArgumentException.ThrowIfNullOrEmpty(bootstrap);\nUseBootstrapServers(bootstrap);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(value))\n{\n    throw new ArgumentException(\"Must not be null or empty\", nameof(value));\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    instrumented.Configure(name);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"name\")\n{\n    logger.LogError(ex, \"'name' must be a non-empty string\");\n}","preventionTips":["Validate strings read from configuration before use","Never default string config values to \"\"; use meaningful defaults or fail fast","Run configuration binding validation at startup"],"tags":["argument-empty","validation","opentelemetry","kafka"],"backgroundTag":"empty-required-field","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"}