VirtualBox

Changeset 22226 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Aug 13, 2009 9:25:03 AM (15 years ago)
Author:
vboxsync
Message:

Main: improve XML error messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xml/Settings.cpp

    r22214 r22226  
    121121
    122122        if (!(m->pelmRoot->getAttributeValue("version", m->strSettingsVersionFull)))
    123             throw ConfigFileError(this, N_("Required VirtualBox/version attribute is missing"));
     123            throw ConfigFileError(this, N_("Required VirtualBox/@version attribute is missing"));
    124124
    125125        m->sv = SettingsVersion_Null;
     
    308308                map[strName] = strValue;
    309309            else
    310                 throw ConfigFileError(this, N_("ExtraDataItem element must have name and value attributes"));
     310                throw ConfigFileError(this, N_("Required ExtraDataItem/@name or @value attribute is missing"));
    311311        }
    312312        else
    313             throw ConfigFileError(this, N_("Invalid element %s in ExtraData section"), pelmExtraDataItem->getName());
     313            throw ConfigFileError(this, N_("Invalid element '%s' in ExtraData section"), pelmExtraDataItem->getName());
    314314    }
    315315}
     
    357357                    flt.action = USBDeviceFilterAction_Hold;
    358358                else
    359                     throw ConfigFileError(this, N_("Invalid value %s in DeviceFilter/action attribute"), strAction.c_str());
     359                    throw ConfigFileError(this, N_("Invalid value '%s' in DeviceFilter/@action attribute"), strAction.c_str());
    360360            }
    361361
     
    532532            }
    533533            else
    534                 throw ConfigFileError(this, N_("MachineEntry element must have uuid and src attributes"));
    535         }
    536         else
    537             throw ConfigFileError(this, N_("Invalid element %s in MachineRegistry section"), pelmChild1->getName());
     534                throw ConfigFileError(this, N_("Required MachineEntry/@uuid or @src attribute is missing"));
     535        }
    538536    }
    539537}
     
    562560        {
    563561            if (!(elmMedium.getAttributeValue("format", med.strFormat)))
    564                 throw ConfigFileError(this, N_("HardDisk element must have format attribute"));
     562                throw ConfigFileError(this, N_("Required HardDisk/@format attribute is missing"));
    565563
    566564            if (!(elmMedium.getAttributeValue("autoReset", med.fAutoReset)))
     
    577575                    med.hdType = HardDiskType_Writethrough;
    578576                else
    579                     throw ConfigFileError(this, N_("HardDisk/type attribute must be one of Normal, Immutable or Writethrough"));
     577                    throw ConfigFileError(this, N_("HardDisk/@type attribute must be one of Normal, Immutable or Writethrough"));
    580578            }
    581579        }
     
    601599                    med.properties[strPropName] = strPropValue;
    602600                else
    603                     throw ConfigFileError(this, N_("HardDisk/Property element must have name and value attributes"));
     601                    throw ConfigFileError(this, N_("Required HardDisk/Property/@name or @value attribute is missing"));
    604602            }
    605603        }
     
    608606    }
    609607    else
    610         throw ConfigFileError(this, N_("%s element must have uuid and location attributes"), elmMedium.getName());
     608        throw ConfigFileError(this, N_("Required %s/@uuid or @location attribute is missing"), elmMedium.getName());
    611609}
    612610
     
    617615void MainConfigFile::readMediaRegistry(const xml::ElementNode &elmMediaRegistry)
    618616{
    619     // <MachineEntry uuid="{ xxx }" src="   xxx "/>
    620617    xml::NodesLoop nl1(elmMediaRegistry);
    621618    const xml::ElementNode *pelmChild1;
     
    630627            t = FloppyImage;
    631628        else
    632             throw ConfigFileError(this, N_("Invalid element %s in MediaRegistry section"), pelmChild1->getName());
     629            continue;
    633630
    634631        xml::NodesLoop nl1(*pelmChild1);
     
    680677                llDhcpServers.push_back(srv);
    681678            else
    682                 throw ConfigFileError(this, N_("DHCPServer element must have networkName, IPAddress, networkMask, lowerIP, upperIP and enabled attributes"));
    683         }
    684         else
    685             throw ConfigFileError(this, N_("Invalid element %s in DHCPServers section"), pelmServer->getName());
     679                throw ConfigFileError(this, N_("Required DHCPServer/@networkName, @IPAddress, @networkMask, @lowerIP, @upperIP or @enabled attribute is missing"));
     680        }
    686681    }
    687682}
     
    740735                            if (pelmLevel4Child->nameEquals("DHCPServers"))
    741736                                readDHCPServers(*pelmLevel4Child);
    742                             else
    743                                 throw ConfigFileError(this, N_("Invalid element %s in NetserviceRegistry section"), pelmLevel4Child->getName());
    744737                        }
    745738                    }
    746739                    else if (pelmGlobalChild->nameEquals("USBDeviceFilters"))
    747740                        readUSBDeviceFilters(*pelmGlobalChild, host.llUSBDeviceFilters);
    748                     else
    749                         throw ConfigFileError(this, N_("Invalid element %s in Global section"), pelmGlobalChild->getName());
    750741                }
    751742            } // end if (pelmRootChild->nameEquals("Global"))
     
    950941
    951942        if (!pelmAdapter->getAttributeValue("slot", nic.ulSlot))
    952             throw ConfigFileError(this, N_("Required Adapter/slot attribute is missing"));
     943            throw ConfigFileError(this, N_("Required Adapter/@slot attribute is missing"));
    953944
    954945        Utf8Str strTemp;
     
    966957                nic.type = NetworkAdapterType_I82545EM;
    967958            else
    968                 throw ConfigFileError(this, N_("Invalid value %s in Adapter/type attribute"), strTemp.c_str());
     959                throw ConfigFileError(this, N_("Invalid value '%s' in Adapter/type attribute"), strTemp.c_str());
    969960        }
    970961
     
    993984            nic.mode = NetworkAttachmentType_Internal;
    994985            if (!pelmAdapterChild->getAttributeValue("name", nic.strName))    // required network name
    995                 throw ConfigFileError(this, N_("Required 'name' element is missing under 'InternalNetwork' element"));
     986                throw ConfigFileError(this, N_("Required InternalNetwork/name element is missing"));
    996987        }
    997988        else if ((pelmAdapterChild = pelmAdapter->findChildElement("HostOnlyInterface")))
     
    999990            nic.mode = NetworkAttachmentType_HostOnly;
    1000991            if (!pelmAdapterChild->getAttributeValue("name", nic.strName))    // required network name
    1001                 throw ConfigFileError(this, N_("Required 'name' element is missing under 'HostOnlyInterface' element"));
     992                throw ConfigFileError(this, N_("Required HostOnlyInterface/name element is missing"));
    1002993        }
    1003994        // else: default is NetworkAttachmentType_Null
     
    10211012        SerialPort port;
    10221013        if (!pelmPort->getAttributeValue("slot", port.ulSlot))
    1023             throw ConfigFileError(this, N_("Required UART/Port/slot attribute is missing"));
     1014            throw ConfigFileError(this, N_("Required UART/Port/@slot attribute is missing"));
    10241015
    10251016        // slot must be unique
     
    10281019             ++it)
    10291020            if ((*it).ulSlot == port.ulSlot)
    1030                 throw ConfigFileError(this, N_("UART/Port/slot attribute value %d is used twice, must be unique"), port.ulSlot);
     1021                throw ConfigFileError(this, N_("UART/Port/@slot attribute value %d is used twice, must be unique"), port.ulSlot);
    10311022
    10321023        if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
    1033             throw ConfigFileError(this, N_("Required UART/Port/enabled attribute is missing"));
     1024            throw ConfigFileError(this, N_("Required UART/Port/@enabled attribute is missing"));
    10341025        if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
    1035             throw ConfigFileError(this, N_("Required UART/Port/IOBase attribute is missing"));
     1026            throw ConfigFileError(this, N_("Required UART/Port/@IOBase attribute is missing"));
    10361027        if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
    1037             throw ConfigFileError(this, N_("Required UART/Port/IRQ attribute is missing"));
     1028            throw ConfigFileError(this, N_("Required UART/Port/@IRQ attribute is missing"));
    10381029
    10391030        Utf8Str strPortMode;
    10401031        if (!pelmPort->getAttributeValue("hostMode", strPortMode))
    1041             throw ConfigFileError(this, N_("Required UART/Port/hostMode attribute is missing"));
     1032            throw ConfigFileError(this, N_("Required UART/Port/@hostMode attribute is missing"));
    10421033        if (strPortMode == "RawFile")
    10431034            port.portMode = PortMode_RawFile;
     
    10491040            port.portMode = PortMode_Disconnected;
    10501041        else
    1051             throw ConfigFileError(this, N_("Invalid value %s in UART/Port/hostMode attribute"), strPortMode.c_str());
     1042            throw ConfigFileError(this, N_("Invalid value '%s' in UART/Port/@hostMode attribute"), strPortMode.c_str());
    10521043
    10531044        pelmPort->getAttributeValue("path", port.strPath);
     
    10721063        ParallelPort port;
    10731064        if (!pelmPort->getAttributeValue("slot", port.ulSlot))
    1074             throw ConfigFileError(this, N_("Required LPT/Port/slot attribute is missing"));
     1065            throw ConfigFileError(this, N_("Required LPT/Port/@slot attribute is missing"));
    10751066
    10761067        // slot must be unique
     
    10791070             ++it)
    10801071            if ((*it).ulSlot == port.ulSlot)
    1081                 throw ConfigFileError(this, N_("LPT/Port/slot attribute value %d is used twice, must be unique"), port.ulSlot);
     1072                throw ConfigFileError(this, N_("LPT/Port/@slot attribute value %d is used twice, must be unique"), port.ulSlot);
    10821073
    10831074        if (!pelmPort->getAttributeValue("enabled", port.fEnabled))
    1084             throw ConfigFileError(this, N_("Required LPT/Port/enabled attribute is missing"));
     1075            throw ConfigFileError(this, N_("Required LPT/Port/@enabled attribute is missing"));
    10851076        if (!pelmPort->getAttributeValue("IOBase", port.ulIOBase))
    1086             throw ConfigFileError(this, N_("Required LPT/Port/IOBase attribute is missing"));
     1077            throw ConfigFileError(this, N_("Required LPT/Port/@IOBase attribute is missing"));
    10871078        if (!pelmPort->getAttributeValue("IRQ", port.ulIRQ))
    1088             throw ConfigFileError(this, N_("Required LPT/Port/IRQ attribute is missing"));
     1079            throw ConfigFileError(this, N_("Required LPT/Port/@IRQ attribute is missing"));
    10891080
    10901081        pelmPort->getAttributeValue("path", port.strPath);
     
    11811172                Utf8Str strDevice;
    11821173                if (!pelmOrder->getAttributeValue("position", ulPos))
    1183                     throw ConfigFileError(this, N_("'Order' element lacks 'position' attribute"));
     1174                    throw ConfigFileError(this, N_("Required Order/@position attribute is missing"));
    11841175                if (!pelmOrder->getAttributeValue("device", strDevice))
    1185                     throw ConfigFileError(this, N_("'Order' element lacks 'device' attribute"));
     1176                    throw ConfigFileError(this, N_("Required Order/@device attribute is missing"));
    11861177                if (hw.mapBootOrder.find(ulPos) != hw.mapBootOrder.end())
    1187                     throw ConfigFileError(this, N_("Value %d of 'position' attribute in 'Order' element is not unique"), ulPos);
     1178                    throw ConfigFileError(this, N_("Order/@attribute value %d is not unique"), ulPos);
    11881179
    11891180                DeviceType_T type;
     
    11991190                    type = DeviceType_Network;
    12001191                else
    1201                     throw ConfigFileError(this, N_("Invalid value %s in Boot/Order/device attribute"), strDevice.c_str());
     1192                    throw ConfigFileError(this, N_("Invalid value '%s' in Boot/Order/@device attribute"), strDevice.c_str());
    12021193                hw.mapBootOrder[ulPos] = type;
    12031194            }
     
    12261217                    hw.vrdpSettings.authType = VRDPAuthType_External;
    12271218                else
    1228                     throw ConfigFileError(this, N_("Invalid value %s in RemoteDisplay/authType attribute"), strAuthType.c_str());
     1219                    throw ConfigFileError(this, N_("Invalid value '%s' in RemoteDisplay/@authType attribute"), strAuthType.c_str());
    12291220            }
    12301221
     
    12591250                        hw.biosSettings.biosBootMenuMode = BIOSBootMenuMode_MessageAndMenu;
    12601251                    else
    1261                         throw ConfigFileError(this, N_("Invalid value %s in BootMenu/mode attribute"), strBootMenuMode.c_str());
     1252                        throw ConfigFileError(this, N_("Invalid value '%s' in BootMenu/@mode attribute"), strBootMenuMode.c_str());
    12621253                }
    12631254            }
     
    12861277                        sctl.controllerType = StorageControllerType_ICH6;
    12871278                    else
    1288                         throw ConfigFileError(this, N_("Invalid value %s for IDEController/type attribute"), strType.c_str());
     1279                        throw ConfigFileError(this, N_("Invalid value '%s' for IDEController/@type attribute"), strType.c_str());
    12891280                }
    12901281                sctl.ulPortCount = 2;
     
    13611352                    hw.audioAdapter.controllerType = AudioControllerType_AC97;
    13621353                else
    1363                     throw ConfigFileError(this, N_("Invalid value %s in AudioAdapter/controller attribute"), strTemp.c_str());
     1354                    throw ConfigFileError(this, N_("Invalid value '%s' in AudioAdapter/@controller attribute"), strTemp.c_str());
    13641355            }
    13651356            if (pelmHwChild->getAttributeValue("driver", strTemp))
     
    13841375                    hw.audioAdapter.driverType = AudioDriverType_MMPM;
    13851376                else
    1386                     throw ConfigFileError(this, N_("Invalid value %s in AudioAdapter/driver attribute"), strTemp.c_str());
     1377                    throw ConfigFileError(this, N_("Invalid value '%s' in AudioAdapter/@driver attribute"), strTemp.c_str());
    13871378            }
    13881379        }
     
    14141405                    hw.clipboardMode = ClipboardMode_Bidirectional;
    14151406                else
    1416                     throw ConfigFileError(this, N_("Invalid value %s in Clipbord/mode attribute"), strTemp.c_str());
     1407                    throw ConfigFileError(this, N_("Invalid value '%s' in Clipbord/@mode attribute"), strTemp.c_str());
    14171408            }
    14181409        }
     
    14251416            readGuestProperties(*pelmHwChild, hw);
    14261417        else
    1427             throw ConfigFileError(this, N_("Invalid element %s in Hardware section"), pelmHwChild->getName());
     1418            throw ConfigFileError(this, N_("Invalid element '%s' in Hardware section"), pelmHwChild->getName());
    14281419    }
    14291420
    14301421    if (hw.ulMemorySizeMB == (uint32_t)-1)
    1431         throw ConfigFileError(this, N_("Required Memory/RAMSize element/attribute is missing"));
     1422        throw ConfigFileError(this, N_("Required Memory/@RAMSize element/attribute is missing"));
    14321423}
    14331424
     
    14661457
    14671458        if (!pelmAttachment->getAttributeValue("hardDisk", strUUID))
    1468             throw ConfigFileError(this, N_("Required HardDiskAttachment/hardDisk attribute is missing"));
     1459            throw ConfigFileError(this, N_("Required HardDiskAttachment/@hardDisk attribute is missing"));
    14691460        parseUUID(att.uuid, strUUID);
    14701461
    14711462        if (!pelmAttachment->getAttributeValue("bus", strBus))
    1472             throw ConfigFileError(this, N_("Required HardDiskAttachment/bus attribute is missing"));
     1463            throw ConfigFileError(this, N_("Required HardDiskAttachment/@bus attribute is missing"));
    14731464        // pre-1.7 'channel' is now port
    14741465        if (!pelmAttachment->getAttributeValue("channel", att.lPort))
    1475             throw ConfigFileError(this, N_("Required HardDiskAttachment/channel attribute is missing"));
     1466            throw ConfigFileError(this, N_("Required HardDiskAttachment/@channel attribute is missing"));
    14761467        // pre-1.7 'device' is still device
    14771468        if (!pelmAttachment->getAttributeValue("device", att.lDevice))
    1478             throw ConfigFileError(this, N_("Required HardDiskAttachment/device attribute is missing"));
     1469            throw ConfigFileError(this, N_("Required HardDiskAttachment/@device attribute is missing"));
    14791470
    14801471        if (strBus == "IDE")
    14811472        {
    14821473            if (!pIDEController)
    1483                 throw ConfigFileError(this, N_("HardDiskAttachment/bus is 'IDE' but cannot find IDE controller"));
     1474                throw ConfigFileError(this, N_("HardDiskAttachment/@bus is 'IDE' but cannot find IDE controller"));
    14841475            pIDEController->llAttachedDevices.push_back(att);
    14851476        }
     
    14871478        {
    14881479            if (!pSATAController)
    1489                 throw ConfigFileError(this, N_("HardDiskAttachment/bus is 'SATA' but cannot find SATA controller"));
     1480                throw ConfigFileError(this, N_("HardDiskAttachment/@bus is 'SATA' but cannot find SATA controller"));
    14901481            pSATAController->llAttachedDevices.push_back(att);
    14911482        }
    14921483        else
    1493             throw ConfigFileError(this, N_("HardDiskAttachment/bus attribute has illegal value '%s'"), strBus.c_str());
     1484            throw ConfigFileError(this, N_("HardDiskAttachment/@bus attribute has illegal value '%s'"), strBus.c_str());
    14941485    }
    14951486}
     
    15151506
    15161507        if (!pelmController->getAttributeValue("name", sctl.strName))
    1517             throw ConfigFileError(this, N_("Required StorageController/name attribute is missing"));
     1508            throw ConfigFileError(this, N_("Required StorageController/@name attribute is missing"));
    15181509        Utf8Str strType;
    15191510        if (!pelmController->getAttributeValue("type", strType))
    1520             throw ConfigFileError(this, N_("Required StorageController/type attribute is missing"));
     1511            throw ConfigFileError(this, N_("Required StorageController/@type attribute is missing"));
    15211512
    15221513        if (strType == "AHCI")
     
    15511542        }
    15521543        else
    1553             throw ConfigFileError(this, N_("Invalid value %s for StorageController/type attribute"), strType.c_str());
     1544            throw ConfigFileError(this, N_("Invalid value '%s' for StorageController/@type attribute"), strType.c_str());
    15541545
    15551546        readStorageControllerAttributes(*pelmController, sctl);
     
    15631554            Utf8Str strTemp;
    15641555            pelmAttached->getAttributeValue("type", strTemp);
    1565             if (strTemp != "HardDisk")
    1566                 throw ConfigFileError(this, N_("AttachedDevice element must have 'HardDisk' type"));
    1567 
    1568             const xml::ElementNode *pelmImage;
    1569             if (!(pelmImage = pelmAttached->findChildElement("Image")))
    1570                 throw ConfigFileError(this, N_("Required AttachedDevice/Image element is missing"));
    1571 
    1572             if (!pelmImage->getAttributeValue("uuid", strTemp))
    1573                 throw ConfigFileError(this, N_("Required AttachedDevice/Image/uuid attributeis missing"));
    1574             parseUUID(att.uuid, strTemp);
    1575 
    1576             if (!pelmAttached->getAttributeValue("port", att.lPort))
    1577                 throw ConfigFileError(this, N_("Required AttachedDevice/port attribute is missing"));
    1578             if (!pelmAttached->getAttributeValue("device", att.lDevice))
    1579                 throw ConfigFileError(this, N_("Required AttachedDevice/device attribute is missing"));
    1580 
    1581             sctl.llAttachedDevices.push_back(att);
     1556            // ignore everything but HardDisk entries for forward compatibility
     1557            if (strTemp == "HardDisk")
     1558            {
     1559                const xml::ElementNode *pelmImage;
     1560                if (!(pelmImage = pelmAttached->findChildElement("Image")))
     1561                    throw ConfigFileError(this, N_("Required AttachedDevice/Image element is missing"));
     1562
     1563                if (!pelmImage->getAttributeValue("uuid", strTemp))
     1564                    throw ConfigFileError(this, N_("Required AttachedDevice/Image/@uuid attribute is missing"));
     1565                parseUUID(att.uuid, strTemp);
     1566
     1567                if (!pelmAttached->getAttributeValue("port", att.lPort))
     1568                    throw ConfigFileError(this, N_("Required AttachedDevice/@port attribute is missing"));
     1569                if (!pelmAttached->getAttributeValue("device", att.lDevice))
     1570                    throw ConfigFileError(this, N_("Required AttachedDevice/@device attribute is missing"));
     1571
     1572                sctl.llAttachedDevices.push_back(att);
     1573            }
    15821574        }
    15831575
     
    16031595
    16041596    if (!elmSnapshot.getAttributeValue("uuid", strTemp))
    1605         throw ConfigFileError(this, N_("Required Snapshot/uuid attribute is missing"));
     1597        throw ConfigFileError(this, N_("Required Snapshot/@uuid attribute is missing"));
    16061598    parseUUID(snap.uuid, strTemp);
    16071599
    16081600    if (!elmSnapshot.getAttributeValue("name", snap.strName))
    1609         throw ConfigFileError(this, N_("Required Snapshot/name attribute is missing"));
     1601        throw ConfigFileError(this, N_("Required Snapshot/@name attribute is missing"));
    16101602
    16111603    elmSnapshot.getAttributeValue("Description", snap.strDescription);
    16121604
    16131605    if (!elmSnapshot.getAttributeValue("timeStamp", strTemp))
    1614         throw ConfigFileError(this, N_("Required Snapshot/timeStamp attribute is missing"));
     1606        throw ConfigFileError(this, N_("Required Snapshot/@timeStamp attribute is missing"));
    16151607    parseTimestamp(snap.timestamp, strTemp);
    16161608
     
    16201612    const xml::ElementNode *pelmHardware;
    16211613    if (!(pelmHardware = elmSnapshot.findChildElement("Hardware")))
    1622         throw ConfigFileError(this, N_("Required Snapshot/Hardware element is missing"));
     1614        throw ConfigFileError(this, N_("Required Snapshot/@Hardware element is missing"));
    16231615    readHardware(*pelmHardware, snap.hardware, snap.storage);
    16241616
     
    16491641                    snap.llChildSnapshots.push_back(child);
    16501642                }
    1651                 else
    1652                     throw ConfigFileError(this, N_("Invalid element %s under Snapshots element"), pelmChildSnapshot->getName());
    16531643            }
    16541644        }
    1655         else if (pelmSnapshotChild->nameEquals("Hardware"))
    1656             ; // handled above
    1657         else
    1658             throw ConfigFileError(this, N_("Invalid element %s under Snapshot element"), pelmSnapshotChild->getName());
    16591645    }
    16601646}
     
    17201706            else if (pelmMachineChild->nameEquals("Description"))
    17211707                strDescription = pelmMachineChild->getValue();
    1722             else if (pelmMachineChild->nameEquals("Hardware"))
    1723                 ; // read above
    1724             else
    1725                 throw ConfigFileError(this, N_("Invalid element %s under Machine element"), pelmMachineChild->getName());
    17261708        }
    17271709    }
    17281710    else
    1729         throw ConfigFileError(this, N_("Machine element must have uuid and name attributes"));
     1711        throw ConfigFileError(this, N_("Required Machine/@uuid or @name attributes is missing"));
    17301712}
    17311713
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette