{"record":{"id":"73ae6c4464416819","repo":"mgth/LittleBigMouse","slug":"value-is-not-a-mac-address-expected-twelve-hexadecimal","errorCode":null,"errorMessage":"'${value}' is not a MAC address: expected twelve hexadecimal digits, optionally grouped by ':', '-' or '.'.","messagePattern":"'(.+?)' is not a MAC address: expected twelve hexadecimal digits, optionally grouped by ':', '-' or '\\.'\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp/Networking/WakeOnLan.cs","lineNumber":30,"sourceCode":"\n    /// <summary>Length of every magic packet: 6 synchronisation bytes + 16 copies of the MAC.</summary>\n    public const int MagicPacketLength = MacLength + 16 * MacLength;\n\n    /// <summary>\n    /// Reads the six address bytes from the usual notations: \"aa:bb:cc:dd:ee:ff\",\n    /// \"AA-BB-CC-DD-EE-FF\", \"aabb.ccdd.eeff\" or twelve bare hexadecimal digits.\n    /// </summary>\n    /// <exception cref=\"FormatException\">The value is not twelve hexadecimal digits.</exception>\n    public static byte[] ParseMacAddress(string macAddress)\n    {\n        ArgumentNullException.ThrowIfNull(macAddress);\n\n        Span<char> digits = stackalloc char[2 * MacLength];\n        var count = 0;\n        foreach (var character in macAddress)\n        {\n            if (character is ':' or '-' or '.' || char.IsWhiteSpace(character)) continue;\n            if (count == digits.Length || !Uri.IsHexDigit(character)) throw NotAMacAddress(macAddress);\n            digits[count++] = character;\n        }\n        if (count != digits.Length) throw NotAMacAddress(macAddress);\n\n        return Convert.FromHexString(digits);\n    }\n\n    /// <summary>Builds the magic packet waking <paramref name=\"macAddress\"/>.</summary>\n    public static byte[] CreateMagicPacket(string macAddress)\n    {\n        var mac = ParseMacAddress(macAddress);\n\n        var packet = new byte[MagicPacketLength];\n        Array.Fill(packet, (byte)0xff, 0, MacLength);\n        for (var offset = MacLength; offset < packet.Length; offset += MacLength) mac.CopyTo(packet, offset);\n        return packet;\n    }\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/mgth/LittleBigMouse/blob/7a42f01d47d99d223b8ee33ba4019af82adf1c48/LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp/Networking/WakeOnLan.cs#L12-L48","documentation":"ParseMacAddress strips separators (':', '-', '.') and whitespace from the input, then copies hex digits into a stack buffer of 2*MacLength characters. It throws NotAMacAddress(macAddress) — with this message — when it encounters either a full buffer followed by another non-separator character, or a character that is not a hex digit. This is the too-many/invalid-character branch at line 30.","triggerScenarios":"Calling ParseMacAddress (or CreateMagicPacket) with a string containing 12+ hex digits plus an invalid 13th+ character, or any non-hex character (e.g. 'G', '_') in the middle, e.g. \"AA:BB:CC:DD:EE:GG\" or \"AA-BB-CC-DD-EE-FF-01\".","commonSituations":"User typo in the Wake-on-LAN target MAC in config; pasting a MAC with a trailing label ('MAC: AA:BB...'); using an IPv4 address or UUID instead of a MAC; copy errors from the TV/device settings screen.","solutions":["Correct the MAC string to contain exactly 12 hex digits (0-9a-fA-F), optionally grouped by ':', '-' or '.', e.g. \"AA:BB:CC:DD:EE:FF\".","Strip any label or trailing text before passing the value: pass only the address itself, not a whole settings line.","Validate in config with a regex ^[0-9A-Fa-f]{2}([:-.]?[0-9A-Fa-f]{2}){5}$ before invoking the API.","Verify you are not passing an IPv4/IP-based identifier where a MAC is required."],"exampleFix":"// before\nvar packet = WakeOnLan.CreateMagicPacket(\"AA:BB:CC:DD:EE:GG\"); // throws\n// after\nvar packet = WakeOnLan.CreateMagicPacket(\"AA:BB:CC:DD:EE:FF\"); // valid hex","handlingStrategy":"validation","validationCode":"static bool LooksLikeMac(string? mac) =>\n    !string.IsNullOrWhiteSpace(mac) &&\n    System.Text.RegularExpressions.Regex.IsMatch(mac, \"^[0-9A-Fa-f]{2}([:-. ]?[0-9A-Fa-f]{2}){5}$\");","typeGuard":"bool IsMacAddress(string? value) =>\n    !string.IsNullOrWhiteSpace(value) &&\n    value.Where(c => c != ':' && c != '-' && c != '.' && !char.IsWhiteSpace(c)).Count() == 12 &&\n    value.Where(c => c != ':' && c != '-' && c != '.' && !char.IsWhiteSpace(c)).All(Uri.IsHexDigit);","tryCatchPattern":"try { var packet = WakeOnLan.CreateMagicPacket(mac); }\ncatch (FormatException e) when (e.Message.Contains(\"not a MAC address\")) {\n    log.LogError(\"Invalid WOL target MAC '{Mac}'\", mac);\n    ui.ShowFieldError(nameof(mac), \"Expected 12 hex digits, optionally grouped by :, - or .\");\n}","preventionTips":["Validate MAC fields with a regex at config-load time, before any WOL call.","Reject inputs with 13+ hex-digit groups or non-hex characters early with a friendly UI message.","Copy MACs exactly as shown on the device screen; strip labels and surrounding text.","Normalize once (remove separators) and store the canonical 12-digit form."],"tags":["mac-address","wake-on-lan","validation","networking"],"backgroundTag":"invalid-identifier-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"}