{"record":{"id":"0b7c79a9a2a53870","repo":"microsoft/aspire","slug":"must-not-be-null-or-whitespace","errorCode":null,"errorMessage":"Must not be null or whitespace","messagePattern":"Must not be null or whitespace","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs","lineNumber":99,"sourceCode":"            {\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            }\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            }","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.ConfluentKafka/Shared/Guard.cs#L81-L117","documentation":"Thrown by Guard.ThrowIfNullOrWhitespace in the vendored ConfluentKafka instrumentation's Guard helper when a required string parameter is null, empty, or consists only of whitespace. It throws ArgumentException naming the parameter via CallerArgumentExpression. It is stricter than ThrowIfNullOrEmpty, rejecting strings like \"   \" as well.","triggerScenarios":"Passing a whitespace-only string to any API that routes through Guard.ThrowIfNullOrWhitespace, e.g. a name or key built from trimmed configuration that ended up as spaces.","commonSituations":"User-supplied input or YAML/JSON config values containing only spaces; values produced by string formatting that collapsed to whitespace; copy-pasted config entries with stray characters.","solutions":["Trim the value and check string.IsNullOrWhiteSpace before passing it in; supply a real non-blank value.","Fix the upstream source (config file, env var, user input) so the value cannot be blank.","Add whitespace validation at your own boundary so it fails with a clearer message."],"exampleFix":"// before\nUseName(rawInput); // \"   \"\n\n// after\nvar name = rawInput?.Trim();\nArgumentException.ThrowIfNullOrWhiteSpace(name);\nUseName(name);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(value))\n{\n    throw new ArgumentException(\"Must not be null or whitespace\", nameof(value));\n}","typeGuard":"static bool IsMeaningful([NotNullWhen(true)] string? value) => !string.IsNullOrWhiteSpace(value);","tryCatchPattern":"try\n{\n    instrumented.Register(name);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"name\")\n{\n    logger.LogError(ex, \"'name' must not be blank\");\n}","preventionTips":["Trim user/config input before validating","Reject blank form/config fields at intake","Add string.IsNullOrWhiteSpace checks before passing names or keys"],"tags":["argument-empty","whitespace","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"}