mgth/LittleBigMouse · error · ArgumentOutOfRangeException

Enter a volume between 0 and 100.

Error message

Enter a volume between 0 and 100.

What it means

VolumePayload converts an integer volume level to the VIDAA protocol string form. VIDAA volume is 0..100, so VolumePayload throws ArgumentOutOfRangeException for any volume outside that range, guarding against sending invalid volume values to the TV.

Solutions

  1. Clamp volume to [0, 100] before calling VolumePayload
  2. Convert other volume scales (float 0..1, 0..255) to integer percentage first
  3. Use Math.Clamp when adjusting volume in steps so it never leaves range
  4. Validate at the UI layer (slider max = 100)

Example fix

// before
var payload = HisenseVidaaProtocol.VolumePayload(rawVolume); // rawVolume may be 0..255
// after
var v = (int)Math.Round(rawVolume / 255.0 * 100);
var payload = HisenseVidaaProtocol.VolumePayload(Math.Clamp(v, 0, 100));
Defensive patterns

Strategy: validation

Validate before calling

if (volume is < 0 or > 100) volume = Math.Clamp(volume, 0, 100);

Try / catch

try { payload = VolumePayload(volume); }
catch (ArgumentOutOfRangeException ex) { volume = Math.Clamp(volume, 0, 100); payload = VolumePayload(volume); }

Prevention

When it happens

Trigger: Calling VolumePayload with volume < 0 or > 100, e.g. passing a dB value, a 0..255 raw level, or an unclamped slider value.

Common situations: Mapping from another API's volume scale (0..255, 0.0..1.0 floats, dB values) without conversion; arithmetic like volume + step pushing past 100.

Related errors


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

Appendix: source

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

                    if (ParsePictureSetting(item) is { } setting) result.Add(setting);
            }
            else if (ParsePictureSetting(root) is { } setting)
            {
                result.Add(setting);
            }
            settings = result;
            return result.Count > 0;
        }
        catch (JsonException)
        {
            return false;
        }
    }

    public static string VolumePayload(int volume)
    {
        if (volume is < 0 or > 100)
            throw new ArgumentOutOfRangeException(nameof(volume), "Enter a volume between 0 and 100.");
        return volume.ToString(CultureInfo.InvariantCulture);
    }

    public static string PlatformActionName(string action)
    {
        var normalized = action.Trim();
        if (normalized.Length is 0 or > 64
            || normalized.Any(c => !char.IsAsciiLetterOrDigit(c) && c is not '_' and not '-'))
            throw new ArgumentException(
                "Enter a platform action name containing only letters, digits, '_' or '-'.",
                nameof(action));
        return normalized;
    }

    public static string ExperimentalLevelPayload(int value)
    {
        if (value is < 0 or > 10)
            throw new ArgumentOutOfRangeException(nameof(value), "Enter a test level between 0 and 10.");

View on GitHub (pinned to 7a42f01d47)