mirror of
https://github.com/akuker/RASCSI.git
synced 2025-01-10 17:30:47 +00:00
More error handing improvements
This commit is contained in:
parent
481dcfd064
commit
5d9c97d676
@ -61,9 +61,7 @@ void Device::SetProtected(bool write_protected)
|
|||||||
void Device::SetVendor(const string& vendor)
|
void Device::SetVendor(const string& vendor)
|
||||||
{
|
{
|
||||||
if (vendor.empty() || vendor.length() > 8) {
|
if (vendor.empty() || vendor.length() > 8) {
|
||||||
ostringstream error;
|
throw illegal_argument_exception("Vendor '" + vendor + "' must be between 1 and 8 characters");
|
||||||
error << "Vendor '" << vendor << "' must be between 1 and 8 characters";
|
|
||||||
throw illegal_argument_exception(error.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->vendor = vendor;
|
this->vendor = vendor;
|
||||||
@ -77,9 +75,7 @@ void Device::SetProduct(const string& product, bool force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (product.empty() || product.length() > 16) {
|
if (product.empty() || product.length() > 16) {
|
||||||
ostringstream error;
|
throw illegal_argument_exception("Product '" + product + "' must be between 1 and 16 characters");
|
||||||
error << "Product '" << product << "' must be between 1 and 16 characters";
|
|
||||||
throw illegal_argument_exception(error.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->product = product;
|
this->product = product;
|
||||||
@ -88,9 +84,7 @@ void Device::SetProduct(const string& product, bool force)
|
|||||||
void Device::SetRevision(const string& revision)
|
void Device::SetRevision(const string& revision)
|
||||||
{
|
{
|
||||||
if (revision.empty() || revision.length() > 4) {
|
if (revision.empty() || revision.length() > 4) {
|
||||||
ostringstream error;
|
throw illegal_argument_exception("Revision '" + revision + "' must be between 1 and 4 characters");
|
||||||
error << "Revision '" << revision << "' must be between 1 and 4 characters";
|
|
||||||
throw illegal_argument_exception(error.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->revision = revision;
|
this->revision = revision;
|
||||||
|
@ -706,19 +706,25 @@ bool ProcessCmd(int fd, const PbDeviceDefinition& pbDevice, const PbOperation op
|
|||||||
|
|
||||||
device->SetId(id);
|
device->SetId(id);
|
||||||
device->SetLun(unit);
|
device->SetLun(unit);
|
||||||
if (!pbDevice.vendor().empty()) {
|
|
||||||
device->SetVendor(pbDevice.vendor());
|
|
||||||
}
|
|
||||||
if (!pbDevice.product().empty()) {
|
|
||||||
device->SetProduct(pbDevice.product());
|
|
||||||
}
|
|
||||||
if (!pbDevice.revision().empty()) {
|
|
||||||
device->SetRevision(pbDevice.revision());
|
|
||||||
}
|
|
||||||
if (!device->IsReadOnly()) {
|
if (!device->IsReadOnly()) {
|
||||||
device->SetProtected(pbDevice.protected_());
|
device->SetProtected(pbDevice.protected_());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!pbDevice.vendor().empty()) {
|
||||||
|
device->SetVendor(pbDevice.vendor());
|
||||||
|
}
|
||||||
|
if (!pbDevice.product().empty()) {
|
||||||
|
device->SetProduct(pbDevice.product());
|
||||||
|
}
|
||||||
|
if (!pbDevice.revision().empty()) {
|
||||||
|
device->SetRevision(pbDevice.revision());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const illegal_argument_exception& e) {
|
||||||
|
return ReturnStatus(fd, false, e.getmsg());
|
||||||
|
}
|
||||||
|
|
||||||
if (pbDevice.block_size()) {
|
if (pbDevice.block_size()) {
|
||||||
Disk *disk = dynamic_cast<Disk *>(device);
|
Disk *disk = dynamic_cast<Disk *>(device);
|
||||||
if (disk && disk->IsSectorSizeConfigurable()) {
|
if (disk && disk->IsSectorSizeConfigurable()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user