babalae/better-genshin-impact · error · ArgumentOutOfRangeException

不支持的相对鼠标输入类型

Error message

不支持的相对鼠标输入类型

What it means

RelativeMouseInputMonitorFactory.Get maps a RelativeMouseInputType to a concrete monitor (DirectInput or RawInput). Any other value (including default(int) cast to the enum, or a future enum member) hits the default arm and throws ArgumentOutOfRangeException. This is a closed-enum guard ensuring only the two supported backends are selected.

Source

Thrown at BetterGenshinImpact/Core/Monitor/RelativeMouseInputMonitorFactory.cs:15

using System;

namespace BetterGenshinImpact.Core.Monitor;

public sealed class RelativeMouseInputMonitorFactory(
    DirectInputMonitor directInputMonitor,
    RawInputMonitor rawInputMonitor) : IRelativeMouseInputMonitorFactory
{
    public IRelativeMouseInputMonitor Get(RelativeMouseInputType type)
    {
        return type switch
        {
            RelativeMouseInputType.DirectInput => directInputMonitor,
            RelativeMouseInputType.RawInput => rawInputMonitor,
            _ => throw new ArgumentOutOfRangeException(nameof(type), type, "不支持的相对鼠标输入类型")
        };
    }
}

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Ensure config always specifies a valid RelativeMouseInputType (DirectInput or RawInput).
  2. Validate the enum value at config load and default to a supported backend.
  3. When extending the enum, update this switch in the same change.

Example fix

// before
var mon = factory.Get(config.RelativeMouseType);

// after
var type = config.RelativeMouseType is RelativeMouseInputType.DirectInput
    or RelativeMouseInputType.RawInput
        ? config.RelativeMouseType
        : RelativeMouseInputType.DirectInput;
var mon = factory.Get(type);
Defensive patterns

Strategy: validation

Validate before calling

var type = config.RelativeMouseType is RelativeMouseInputType.DirectInput
    or RelativeMouseInputType.RawInput
        ? config.RelativeMouseType
        : RelativeMouseInputType.DirectInput;
var mon = factory.Get(type);

Type guard

static bool IsSupported(RelativeMouseInputType t) => t is RelativeMouseInputType.DirectInput or RelativeMouseInputType.RawInput;

Prevention

When it happens

Trigger: Passing an unconfigured/default RelativeMouseInputType; reading the type from config that was never set; an enum value added without updating the factory.

Common situations: Default-initialized config object whose MouseInputType field defaults to 0 (not a valid member); config schema drift; new enum member added to RelativeMouseInputType but not handled here.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/0a2a9a49641d5a2b. Report an issue: GitHub.