{"record":{"id":"73d67cc12d595cfb","repo":"restsharp/RestSharp","slug":"parameter-cannot-be-an-empty-string","errorCode":null,"errorMessage":"Parameter cannot be an empty string","messagePattern":"Parameter cannot be an empty string","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/RestSharp/Ensure.cs","lineNumber":24,"sourceCode":"// \n// http://www.apache.org/licenses/LICENSE-2.0\n// \n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nnamespace RestSharp;\n\nstatic class Ensure {\n    public static T NotNull<T>(T? value, [InvokerParameterName] string name) => value ?? throw new ArgumentNullException(name);\n\n    public static string NotEmptyString(object? value, [InvokerParameterName] string name) {\n        var s = value as string ?? value?.ToString();\n        if (s == null) throw new ArgumentNullException(name);\n\n        return string.IsNullOrWhiteSpace(s) ? throw new ArgumentException(\"Parameter cannot be an empty string\", name) : s;\n    }\n}","sourceCodeStart":6,"sourceCodeEnd":26,"githubUrl":"https://github.com/restsharp/RestSharp/blob/6a5082169257438cd085f822f050d93256a8e499/src/RestSharp/Ensure.cs#L6-L26","documentation":"Thrown by Ensure.NotEmptyString when the supplied value, after coercion to a string, is null, empty, or whitespace. This is a shared guard used across the library (e.g. ContentType construction, parameter names) to reject blank string arguments.","triggerScenarios":"Calling an API that delegates to Ensure.NotEmptyString with a null, empty, or whitespace-only string argument, such as constructing a ContentType from a blank string, or passing a blank parameter name.","commonSituations":"Reading content-type or parameter name from config that resolved to empty; passing string.Empty inadvertently; whitespace-only values from trimmed user input.","solutions":["Ensure the argument passed to the guarded API is a non-empty, non-whitespace string.","Validate inputs at the call site before invoking the RestSharp API.","Supply sensible defaults when config-driven strings may be empty."],"exampleFix":"// before\nvar ct = (ContentType)(config.ContentType ?? \"\"); // empty config\n\n// after\nvar ctStr = string.IsNullOrWhiteSpace(config.ContentType) ? \"application/json\" : config.ContentType;\nvar ct = (ContentType)ctStr;","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException(\"Value must be a non-empty, non-whitespace string\", nameof(value));","typeGuard":"static bool IsNonEmptyString(string? s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { /* RestSharp API call guarded by Ensure.NotEmptyString */ } catch (ArgumentException ex) when (ex.Message.Contains(\"empty string\")) { /* supply a valid default */ }","preventionTips":["Validate config-sourced strings for null/empty/whitespace before passing to RestSharp.","Provide defaults for optional string configuration values."],"tags":["validation","argument","guard"],"backgroundTag":null,"analyzedSha":"6a5082169257438cd085f822f050d93256a8e499","analyzedAt":"2026-08-13T20:38:25.807Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}