babalae/better-genshin-impact · error · ArgumentException

未知的地图类型: {mapType}

Error message

未知的地图类型: {mapType}

What it means

Thrown by MapManager.CreateMap in the SIFT matching-method branch when mapType is not one of the handled enum values (Teyvat, TheChasm, Enkanomiya, AncientSacredMountain, SeaOfBygoneEras, TempleOfSpace, MoonCanon). The switch's default arm throws ArgumentException. This is a defensive exhaustiveness check — every defined MapTypes member is handled, so it fires only for an out-of-range/undefined enum value.

Source

Thrown at BetterGenshinImpact/GameTask/Common/Map/Maps/MapManager.cs:63

            _maps[key] = map;
            return map;
        }
    }

    private static ISceneMap CreateMap(MapTypes mapType, string matchingMethod)
    {
        if (matchingMethod == "SIFT")
        {
            return mapType switch
            {
                MapTypes.Teyvat => new TeyvatMap(),
                MapTypes.TheChasm => new TheChasmMap(),
                MapTypes.Enkanomiya => new EnkanomiyaMap(),
                MapTypes.AncientSacredMountain => new AncientSacredMountainMap(),
                MapTypes.SeaOfBygoneEras => new SeaOfBygoneErasMap(),
                MapTypes.TempleOfSpace => new TempleOfSpaceMap(),
                MapTypes.MoonCanon => new MoonCanonMap(),
                _ => throw new System.ArgumentException($"未知的地图类型: {mapType}", nameof(mapType))
            };
        }
        else
        {
            return mapType switch
            {
                MapTypes.Teyvat => new TeyvatMapTest(),
                MapTypes.TheChasm => new TheChasmMapTest(),
                MapTypes.Enkanomiya => new EnkanomiyaMapTest(),
                MapTypes.AncientSacredMountain => new AncientSacredMountainMap(),
                MapTypes.SeaOfBygoneEras => new SeaOfBygoneErasMap(),
                MapTypes.TempleOfSpace => new TempleOfSpaceMap(),
                MapTypes.MoonCanon => new MoonCanonMap(),
                _ => throw new System.ArgumentException($"未知的地图类型: {mapType}", nameof(mapType))
            };
        }
    }
}

View on GitHub (pinned to a7cb36712d)

Solutions

  1. If you added a new MapTypes member, add its case to both switch expressions in CreateMap (lines 54 and 68).
  2. Validate the mapType value is a defined enum member before calling GetMap (Enum.IsDefined).
  3. Check the originating config/pathing data for an invalid map-type code and correct it to a supported value.

Example fix

// before
_ => throw new System.ArgumentException($"未知的地图类型: {mapType}", nameof(mapType))

// after — keep the guard, but ensure every enum member is mapped; if you just added a member add its case:
MapTypes.NewRegion => new NewRegionMap(),
_ => throw new System.ArgumentException($"未知的地图类型: {mapType}", nameof(mapType))
Defensive patterns

Strategy: type-guard

Validate before calling

if (!Enum.IsDefined(mapType)) throw new ArgumentException($"无效的地图类型枚举值: {mapType}");

Type guard

static bool IsKnownSiftMapType(MapTypes t) => t is MapTypes.Teyvat or MapTypes.TheChasm or MapTypes.Enkanomiya or MapTypes.AncientSacredMountain or MapTypes.SeaOfBygoneEras or MapTypes.TempleOfSpace or MapTypes.MoonCanon;

Prevention

When it happens

Trigger: GetMap(mapType, "SIFT") is called with an enum value outside the known set. Since MapTypes is a closed enum and all members are listed, this requires either an invalid cast (e.g. (MapTypes)999) or a newly added enum member whose SIFT map class hasn't been implemented yet.

Common situations: A new MapTypes member was added to the enum but no corresponding 'new XxxMap()' case was added in the SIFT branch; an external caller cast an arbitrary int to MapTypes; config/job data referenced a map type code that mapped to an undefined enum value.

Related errors


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