mgth/LittleBigMouse · error · ArgumentException

Enter the four-digit PIN displayed by the Hisense device.

Error message

Enter the four-digit PIN displayed by the Hisense device.

What it means

PinPayload converts a 4-digit numeric PIN into the JSON pairing payload ({authNum: <int>}) for Hisense VIDAA authentication. It requires exactly 4 ASCII digits; anything else (wrong length, non-digit characters, null-ish content) throws ArgumentException so an invalid pairing code is never serialized or sent to the device.

Solutions

  1. Validate that the entered PIN is exactly 4 ASCII digits (Regex ^[0-9]{4}$) before calling PinPayload.
  2. Trim and sanitize the input field, and restrict the text box to numeric input with MaxLength=4.
  3. Re-display the PIN on the Hisense device and have the user re-enter it.
  4. Catch ArgumentException and show the message 'Enter the four-digit PIN displayed by the Hisense device.'

Example fix

// before
var payload = PinPayload(pinInput.Text); // may be "12 4" or "123"
// after
var pin = pinInput.Text?.Trim() ?? "";
if (System.Text.RegularExpressions.Regex.IsMatch(pin, "^[0-9]{4}$"))
    var payload = PinPayload(pin);
Defensive patterns

Strategy: validation

Validate before calling

public static bool IsValidPin(string? pin) =>
    pin is not null && pin.Length == 4 && pin.All(char.IsAsciiDigit);

Type guard

public static bool IsFourDigitPin(string? s) => !string.IsNullOrEmpty(s) && s.Length == 4 && s.All(char.IsAsciiDigit);

Try / catch

try { var payload = HisenseVidaaProtocol.PinPayload(pin); }
catch (ArgumentException) { ShowError("Enter the four-digit PIN displayed by the Hisense device."); }

Prevention

When it happens

Trigger: Calling PinPayload with a PIN string whose Length != 4, or containing non-digit characters (letters, spaces, dashes, unicode digits), e.g. PinPayload("12a4"), PinPayload("123"), PinPayload("12345").

Common situations: User typing the PIN shown on the TV with a typo or trailing space; pasting a PIN that includes formatting; capturing only part of the code from the screen; binding a text field that allows arbitrary characters; confusing the new PIN payload with the legacy string variant.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of mgth/LittleBigMouse@7a42f01d47 (2026-09-16). Data as JSON: /api/errors/7ba9faff3451d678. Report an issue: GitHub.

Appendix: source

Thrown at LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp.Avalonia/HisenseVidaa/HisenseVidaaProtocol.cs:265

    ];

    public static IReadOnlyList<string> LegacyResponseTopics(string deviceTopic) =>
    [
        $"/remoteapp/mobile/{deviceTopic}/#",
        "/remoteapp/mobile/broadcast/#",
    ];

    public static string PairingRequestPayload() => JsonSerializer.Serialize(new
    {
        app_version = 2,
        connect_result = 0,
        device_type = "Mobile App",
    });

    public static string PinPayload(string pin)
    {
        if (pin.Length != 4 || !pin.All(char.IsAsciiDigit))
            throw new ArgumentException("Enter the four-digit PIN displayed by the Hisense device.", nameof(pin));
        return JsonSerializer.Serialize(new { authNum = int.Parse(pin, CultureInfo.InvariantCulture) });
    }

    public static string LegacyPinPayload(string pin)
    {
        if (pin.Length != 4 || !pin.All(char.IsAsciiDigit))
            throw new ArgumentException("Enter the four-digit PIN displayed by the Hisense device.", nameof(pin));
        return JsonSerializer.Serialize(new { authNum = pin });
    }

    public static string NormalizeMac(string? value, bool preserveCase = false)
    {
        if (string.IsNullOrWhiteSpace(value)) return "";
        var compact = new string(value.Where(Uri.IsHexDigit).ToArray());
        if (compact.Length != 12) return value.Trim();
        var result = string.Join(':', Enumerable.Range(0, 6).Select(i => compact.Substring(i * 2, 2)));
        return preserveCase ? result : result.ToUpperInvariant();
    }

View on GitHub (pinned to 7a42f01d47)