[Harness] If empty nodes are found, do not crash. (#8201)
Looks like we have cases in which we get empty nodes when listing devices, which makes the parsing of the nodes fail and crash. Move the code to a diff method, try to parse the data, if there is an exception (missing data) return null. If null is returned, do not add it. Fixes: https://github.com/xamarin/xamarin-macios/issues/8160
This commit is contained in:
Родитель
f1508bff64
Коммит
728442e01f
|
@ -58,6 +58,33 @@ namespace Xharness.Hardware {
|
||||||
return LoadAsync (log, extra_data: false, removed_locked: !include_locked, force: force);
|
return LoadAsync (log, extra_data: false, removed_locked: !include_locked, force: force);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Device GetDevice (XmlNode deviceNone)
|
||||||
|
{
|
||||||
|
// get data, if we are missing some of them, we will return null, happens sometimes that we
|
||||||
|
// have some empty nodes. We could do this with try/catch, but we want to throw the min amount
|
||||||
|
// of exceptions. We do know that we will have issues with the parsing of the DeviceClass, check
|
||||||
|
// the value, and if is there, get the rest, else return null
|
||||||
|
var usable = deviceNone.SelectSingleNode ("IsUsableForDebugging")?.InnerText;
|
||||||
|
if (Enum.TryParse<DeviceClass> (deviceNone.SelectSingleNode ("DeviceClass")?.InnerText, true, out var deviceClass)) {
|
||||||
|
var device = new Device {
|
||||||
|
DeviceIdentifier = deviceNone.SelectSingleNode ("DeviceIdentifier")?.InnerText,
|
||||||
|
DeviceClass = deviceClass,
|
||||||
|
CompanionIdentifier = deviceNone.SelectSingleNode ("CompanionIdentifier")?.InnerText,
|
||||||
|
Name = deviceNone.SelectSingleNode ("Name")?.InnerText,
|
||||||
|
BuildVersion = deviceNone.SelectSingleNode ("BuildVersion")?.InnerText,
|
||||||
|
ProductVersion = deviceNone.SelectSingleNode ("ProductVersion")?.InnerText,
|
||||||
|
ProductType = deviceNone.SelectSingleNode ("ProductType")?.InnerText,
|
||||||
|
InterfaceType = deviceNone.SelectSingleNode ("InterfaceType")?.InnerText,
|
||||||
|
IsUsableForDebugging = usable == null ? (bool?) null : ((bool?) (usable == "True")),
|
||||||
|
};
|
||||||
|
bool.TryParse (deviceNone.SelectSingleNode ("IsLocked")?.InnerText, out var locked);
|
||||||
|
device.IsLocked = locked;
|
||||||
|
return device;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task LoadAsync (ILog log, bool extra_data = false, bool removed_locked = false, bool force = false)
|
public async Task LoadAsync (ILog log, bool extra_data = false, bool removed_locked = false, bool force = false)
|
||||||
{
|
{
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
|
@ -94,20 +121,9 @@ namespace Xharness.Hardware {
|
||||||
doc.LoadWithoutNetworkAccess (tmpfile);
|
doc.LoadWithoutNetworkAccess (tmpfile);
|
||||||
|
|
||||||
foreach (XmlNode dev in doc.SelectNodes ("/MTouch/Device")) {
|
foreach (XmlNode dev in doc.SelectNodes ("/MTouch/Device")) {
|
||||||
var usable = dev.SelectSingleNode ("IsUsableForDebugging")?.InnerText;
|
var d = GetDevice (dev);
|
||||||
Device d = new Device {
|
if (d == null)
|
||||||
DeviceIdentifier = dev.SelectSingleNode ("DeviceIdentifier")?.InnerText,
|
continue;
|
||||||
DeviceClass = (DeviceClass) Enum.Parse(typeof(DeviceClass), dev.SelectSingleNode ("DeviceClass")?.InnerText, true),
|
|
||||||
CompanionIdentifier = dev.SelectSingleNode ("CompanionIdentifier")?.InnerText,
|
|
||||||
Name = dev.SelectSingleNode ("Name")?.InnerText,
|
|
||||||
BuildVersion = dev.SelectSingleNode ("BuildVersion")?.InnerText,
|
|
||||||
ProductVersion = dev.SelectSingleNode ("ProductVersion")?.InnerText,
|
|
||||||
ProductType = dev.SelectSingleNode ("ProductType")?.InnerText,
|
|
||||||
InterfaceType = dev.SelectSingleNode ("InterfaceType")?.InnerText,
|
|
||||||
IsUsableForDebugging = usable == null ? (bool?)null : ((bool?)(usable == "True")),
|
|
||||||
};
|
|
||||||
bool.TryParse (dev.SelectSingleNode ("IsLocked")?.InnerText, out var locked);
|
|
||||||
d.IsLocked = locked;
|
|
||||||
if (removed_locked && d.IsLocked) {
|
if (removed_locked && d.IsLocked) {
|
||||||
log.WriteLine ($"Skipping device {d.Name} ({d.DeviceIdentifier}) because it's locked.");
|
log.WriteLine ($"Skipping device {d.Name} ({d.DeviceIdentifier}) because it's locked.");
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1,6 +1,40 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<MTouch Version="0" Revision="0">
|
<MTouch Version="0" Revision="0">
|
||||||
<SdkRoot>/Applications/Xcode113.app/Contents/Developer</SdkRoot>
|
<SdkRoot>/Applications/Xcode113.app/Contents/Developer</SdkRoot>
|
||||||
|
<Device>
|
||||||
|
<ActivationState />
|
||||||
|
<AmountDataAvailable />
|
||||||
|
<BatteryCurrentCapacity />
|
||||||
|
<BluetoothAddress />
|
||||||
|
<BuildVersion />
|
||||||
|
<ChipID />
|
||||||
|
<CPUArchitecture />
|
||||||
|
<DeveloperStatus />
|
||||||
|
<DeviceClass />
|
||||||
|
<DeviceColor />
|
||||||
|
<DeviceEnclosureColor />
|
||||||
|
<DeviceIdentifier>5696DC36EE3249859D465DA37E6EA912</DeviceIdentifier>
|
||||||
|
<DevToolsAvailable />
|
||||||
|
<EnableWifiDebugging />
|
||||||
|
<HardwareModel />
|
||||||
|
<InterfaceType>Wifi</InterfaceType>
|
||||||
|
<InternationalMobileEquipmentIdentity />
|
||||||
|
<IsPaired>False</IsPaired>
|
||||||
|
<IsUsableForDebugging />
|
||||||
|
<IsValid>True</IsValid>
|
||||||
|
<ModelNumber />
|
||||||
|
<Name>Office</Name>
|
||||||
|
<PasswordProtected />
|
||||||
|
<ProductionSOC />
|
||||||
|
<ProductType />
|
||||||
|
<ProductVersion />
|
||||||
|
<SerialNumber />
|
||||||
|
<TotalDataCapacity />
|
||||||
|
<UDID />
|
||||||
|
<UniqueChipID />
|
||||||
|
<WatchCompanionCapability />
|
||||||
|
<WiFiAddress />
|
||||||
|
</Device>
|
||||||
<Device>
|
<Device>
|
||||||
<ActivationState>Activated</ActivationState>
|
<ActivationState>Activated</ActivationState>
|
||||||
<AmountDataAvailable>5650776064</AmountDataAvailable>
|
<AmountDataAvailable>5650776064</AmountDataAvailable>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче