{"record":{"id":"61447dd3e6ef8237","repo":"git-ecosystem/git-credential-manager","slug":"argument-cannot-be-empty-or-white-space","errorCode":null,"errorMessage":"Argument cannot be empty or white space.","messagePattern":"Argument cannot be empty or white space\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Core/EnsureArgument.cs","lineNumber":31,"sourceCode":"        }\n\n        public static void NotNullOrEmpty(string arg, string name)\n        {\n            NotNull(arg, name);\n\n            if (string.IsNullOrEmpty(arg))\n            {\n                throw new ArgumentException(\"Argument cannot be empty.\", name);\n            }\n        }\n\n        public static void NotNullOrWhiteSpace(string arg, string name)\n        {\n            NotNull(arg, name);\n\n            if (string.IsNullOrWhiteSpace(arg))\n            {\n                throw new ArgumentException(\"Argument cannot be empty or white space.\", name);\n            }\n        }\n\n        public static void AbsoluteUri(Uri arg, string name)\n        {\n            NotNull(arg, name);\n\n            if (!arg.IsAbsoluteUri)\n            {\n                throw new ArgumentException(\"Argument must be an absolute URI.\", name);\n            }\n        }\n\n        public static void PositiveOrZero(int arg, string name)\n        {\n            if (arg < 0)\n            {\n                throw new ArgumentOutOfRangeException(name, \"Argument must be positive or zero (non-negative).\");","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/EnsureArgument.cs#L13-L49","documentation":"This ArgumentException is thrown by EnsureArgument.NotNullOrWhiteSpace when a required string argument is null, empty, or contains only whitespace. The library treats empty/whitespace strings as invalid because downstream code depends on a meaningful value. The parameter name is passed to ArgumentException so the caller can identify the offending argument.","triggerScenarios":"Calling EnsureArgument.NotNullOrWhiteSpace(arg, name) when arg is null, \"\", or consists only of spaces/tabs/newlines. Note NotNull(arg, name) runs first, so a null arg throws ArgumentNullException from NotNull rather than this message.","commonSituations":"Passing an unset environment variable or empty config value as an API key, host, or connection string; trimming user input to an empty string; a deserialized object with a blank required field.","solutions":["Ensure the string argument is non-empty and contains at least one non-whitespace character before calling the API that validates it","Check the source of the value (config file, env var, user input) and fix the upstream producer that yields an empty/whitespace value","If null is the issue, note the message comes from NotNull first; supply an actual string object","Add validation or defaults at application startup so blank values fail early with a clearer message"],"exampleFix":"// before\nEnsureArgument.NotNullOrWhiteSpace(apiKey, nameof(apiKey)); // throws when apiKey = \"   \"\n// after\nif (string.IsNullOrWhiteSpace(apiKey))\n    throw new InvalidOperationException(\"apiKey must be configured; set API_KEY env var\");\nEnsureArgument.NotNullOrWhiteSpace(apiKey, nameof(apiKey));","handlingStrategy":"validation","validationCode":"public static bool IsValidNonWhiteSpace(string s) => !string.IsNullOrWhiteSpace(s);\n// usage: if (!IsValidNonWhiteSpace(apiKey)) throw new InvalidOperationException(\"apiKey required\");","typeGuard":"static bool HasValue(string? s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { EnsureArgument.NotNullOrWhiteSpace(value, nameof(value)); }\ncatch (ArgumentException ex) when (ex.ParamName == nameof(value))\n{\n    logger.LogWarning(\"Value for {Param} was empty; using default\", ex.ParamName);\n    value = defaultValue;\n}","preventionTips":["Check string.IsNullOrWhiteSpace at config-load time and fail fast with a clear message","Use nullable reference types (string?) to force null handling at compile time","Centralize required-string validation in one startup step","Never pass raw env vars or user input straight into validated APIs without trimming and checking"],"tags":["argument-validation","csharp","null-or-whitespace"],"backgroundTag":"empty-required-field","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}