More error handing improvements

This commit is contained in:
Uwe Seimet 2021-08-28 15:26:31 +02:00
parent 481dcfd064
commit 5d9c97d676
2 changed files with 18 additions and 18 deletions

View File

@ -61,9 +61,7 @@ void Device::SetProtected(bool write_protected)
void Device::SetVendor(const string& vendor)
{
if (vendor.empty() || vendor.length() > 8) {
ostringstream error;
error << "Vendor '" << vendor << "' must be between 1 and 8 characters";
throw illegal_argument_exception(error.str());
throw illegal_argument_exception("Vendor '" + vendor + "' must be between 1 and 8 characters");
}
this->vendor = vendor;
@ -77,9 +75,7 @@ void Device::SetProduct(const string& product, bool force)
}
if (product.empty() || product.length() > 16) {
ostringstream error;
error << "Product '" << product << "' must be between 1 and 16 characters";
throw illegal_argument_exception(error.str());
throw illegal_argument_exception("Product '" + product + "' must be between 1 and 16 characters");
}
this->product = product;
@ -88,9 +84,7 @@ void Device::SetProduct(const string& product, bool force)
void Device::SetRevision(const string& revision)
{
if (revision.empty() || revision.length() > 4) {
ostringstream error;
error << "Revision '" << revision << "' must be between 1 and 4 characters";
throw illegal_argument_exception(error.str());
throw illegal_argument_exception("Revision '" + revision + "' must be between 1 and 4 characters");
}
this->revision = revision;

View File

@ -706,19 +706,25 @@ bool ProcessCmd(int fd, const PbDeviceDefinition& pbDevice, const PbOperation op
device->SetId(id);
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()) {
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()) {
Disk *disk = dynamic_cast<Disk *>(device);
if (disk && disk->IsSectorSizeConfigurable()) {