{"record":{"id":"f291a3f30c7ca2be","repo":"babalae/better-genshin-impact","slug":"description","errorCode":null,"errorMessage":"无法找到描述为 '{description}' 的枚举值","messagePattern":"无法找到描述为 '(.+?)' 的枚举值","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"BetterGenshinImpact/GameTask/Common/Map/Maps/Base/MapTypes.cs","lineNumber":43,"sourceCode":"\n    [Description(\"霜月\")]\n    MoonCanon,\n}\npublic static class MapTypesExtensions\n{\n    public static MapTypes ParseFromDescription(string description)\n    {\n        foreach (var field in typeof(MapTypes).GetFields())\n        {\n            if (Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute)\n            {\n                if (attribute.Description == description)\n                {\n                    return (MapTypes)field.GetValue(null)!;\n                }\n            }\n        }\n        throw new ArgumentException($\"无法找到描述为 '{description}' 的枚举值\", nameof(description));\n    }\n    \n    public static MapTypes ParseFromName(string name)\n    {\n        if (Enum.TryParse<MapTypes>(name, true, out var result))\n        {\n            return result;\n        }\n        throw new ArgumentException($\"无法找到名称为 '{name}' 的枚举值\", nameof(name));\n    }\n}","sourceCodeStart":25,"sourceCodeEnd":54,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/Common/Map/Maps/Base/MapTypes.cs#L25-L54","documentation":"Thrown by MapTypesExtensions.ParseFromDescription when no enum field's [Description] attribute matches the input string exactly. The method reflects over typeof(MapTypes).GetFields() and compares attribute.Description == description with ordinal equality (case-sensitive). If none match, it throws ArgumentException. Used to convert a human-readable map name (e.g. '提瓦特大陆') back to the MapTypes enum.","triggerScenarios":"ParseFromDescription is called with a string that doesn't exactly equal any [Description(...)] value. Trailing whitespace, different casing, a translated/renamed label, or a description for a member that was removed will all fail the exact-match comparison.","commonSituations":"Game/config label was localized differently or updated; user typed a map name with extra spaces or full-width characters; the description string in config doesn't match the attribute text byte-for-byte; a previous enum member (and its description) was deleted but old config still references it.","solutions":["Trim and normalize the input string before parsing; compare the value against the known descriptions in MapTypes.cs.","Update the config label to exactly match a [Description] attribute value.","If a description changed, update the attribute or add a compatibility alias.","Consider case-insensitive or trimmed matching in ParseFromDescription if labels are user-supplied."],"exampleFix":"// before — exact match only\nif (attribute.Description == description) { ... }\n\n// after — tolerant of whitespace/casing\nif (string.Equals(attribute.Description, description?.Trim(), StringComparison.OrdinalIgnoreCase)) { ... }","handlingStrategy":"validation","validationCode":"var known = typeof(MapTypes).GetFields()\n    .Select(f => Attribute.GetCustomAttribute(f, typeof(DescriptionAttribute)) as DescriptionAttribute)\n    .Where(a => a != null).Select(a => a!.Description).ToHashSet();\nif (!known.Contains(description?.Trim())) throw new ArgumentException($\"未知的地图描述: {description}\");","typeGuard":"static bool IsValidMapDescription(string? d) => typeof(MapTypes).GetFields()\n    .Any(f => Attribute.GetCustomAttribute(f, typeof(DescriptionAttribute)) is DescriptionAttribute a && a.Description == d);","tryCatchPattern":null,"preventionTips":["Keep config map labels exactly matching the [Description] attributes.","Trim user-supplied labels before parsing."],"tags":["enum","reflection","description-attribute","parsing","config"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}