{"record":{"id":"c0a49acf0e824575","repo":"mgth/LittleBigMouse","slug":"enter-a-valid-ipv4-address","errorCode":null,"errorMessage":"Enter a valid IPv4 address.","messagePattern":"Enter a valid IPv4 address\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp/Networking/Ipv4Address.cs","lineNumber":43,"sourceCode":"    {\n        address = null;\n        if (string.IsNullOrWhiteSpace(value)) return false;\n        if (!IPAddress.TryParse(value.Trim(), out var parsed)\n            || parsed.AddressFamily != AddressFamily.InterNetwork) return false;\n\n        address = parsed;\n        return true;\n    }\n\n    /// <summary>\n    /// Returns the address without its surrounding blanks, so callers store and send the same\n    /// text they validated.\n    /// </summary>\n    /// <exception cref=\"ArgumentException\">The value is not a literal IPv4 address.</exception>\n    public static string Require(string? value, string parameterName, string? message = null)\n        => IsValid(value)\n            ? value.Trim()\n            : throw new ArgumentException(message ?? InvalidMessage, parameterName);\n}\n","sourceCodeStart":25,"sourceCodeEnd":45,"githubUrl":"https://github.com/mgth/LittleBigMouse/blob/7a42f01d47d99d223b8ee33ba4019af82adf1c48/LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp/Networking/Ipv4Address.cs#L25-L45","documentation":"Ipv4Address.Require validates that a string is a literal IPv4 address and returns it trimmed; otherwise it throws ArgumentException naming the offending parameter. The library centralizes IPv4 validation so callers get a consistent error with an optional custom message (InvalidMessage by default: 'Enter a valid IPv4 address.').","triggerScenarios":"Passing a null, empty, hostname (e.g. 'mytv.local'), IPv6, or malformed string (e.g. '192.168.1.999', '192.168.1') to Ipv4Address.Require, or to any API whose parameter is validated through it.","commonSituations":"User typed a hostname instead of an IP in settings; copy-paste with stray characters or whitespace-only input; display configured via DHCP so the user entered a stale or wrong address; transposed digits producing an out-of-range octet.","solutions":["Validate the input with Ipv4Address.IsValid before passing it to APIs that call Require","Convert hostnames to IP addresses first (DNS/DNS-SD lookup) — Require only accepts literal IPv4","Show an inline IP-format validator in the UI so malformed input never reaches the service","Catch ArgumentException and surface the parameter name/message to the user"],"exampleFix":"// before\nservice.Associate(monitorId, userInput); // throws ArgumentException\n// after\nif (!Ipv4Address.IsValid(userInput))\n    throw new ArgumentException(\"Enter a valid IPv4 address.\", nameof(userInput));\nservice.Associate(monitorId, Ipv4Address.Require(userInput, nameof(userInput)));","handlingStrategy":"validation","validationCode":"if (!Ipv4Address.IsValid(userInput))\n    throw new ArgumentException(\"Enter a valid IPv4 address.\", nameof(userInput));","typeGuard":"static bool IsLiteralIPv4(string? s) => Ipv4Address.IsValid(s);","tryCatchPattern":"try\n{\n    value = Ipv4Address.Require(input, nameof(input));\n}\ncatch (ArgumentException ex)\n{\n    // show ex.Message to the user and re-prompt for the IP\n}","preventionTips":["Use IsValid to gate inputs at the UI boundary","Reject hostnames early — resolve them separately before calling Require","Trim user input and reject empty/whitespace strings","Range-check octets (0-255) in custom editors before submitting"],"tags":["validation","ipv4","argument","format"],"backgroundTag":"invalid-argument-format","analyzedSha":"7a42f01d47d99d223b8ee33ba4019af82adf1c48","analyzedAt":"2026-09-16T00:35:00.514Z","contentChangedAt":"2026-09-16T00:35:00.514Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}