Made some error messages more concise

This commit is contained in:
Uwe Seimet 2021-08-28 14:34:58 +02:00
parent b9633ea46f
commit 095157ccbe
3 changed files with 22 additions and 10 deletions

View File

@ -64,6 +64,9 @@ Device *DeviceFactory::CreateDevice(PbDeviceType& type, const string& filename,
else if (filename == "daynaport") { else if (filename == "daynaport") {
type = SCDP; type = SCDP;
} }
else {
return NULL;
}
} }
Device *device = NULL; Device *device = NULL;

View File

@ -650,10 +650,10 @@ bool ProcessCmd(int fd, const PbDeviceDefinition& pbDevice, const PbOperation op
ostringstream s; ostringstream s;
s << (dryRun ? "Validating: " : "Executing: "); s << (dryRun ? "Validating: " : "Executing: ");
s << "operation=" << PbOperation_Name(operation) << ", command params='" << params << "'" s << "operation=" << PbOperation_Name(operation) << ", command params='" << params
<< ", device id=" << id << ", unit=" << unit << ", type=" << PbDeviceType_Name(type) << "', device id=" << id << ", unit=" << unit << ", type=" << PbDeviceType_Name(type)
<< ", params='" << pbDevice.params() << "', vendor='" << pbDevice.vendor() << ", params='" << pbDevice.params() << "', vendor='" << pbDevice.vendor()
<< ", product='" << pbDevice.product() << "', revision='" << pbDevice.revision() << "'" << "', product='" << pbDevice.product() << "', revision='" << pbDevice.revision()
<< "', block size=" << pbDevice.block_size(); << "', block size=" << pbDevice.block_size();
LOGINFO("%s", s.str().c_str()); LOGINFO("%s", s.str().c_str());
@ -677,21 +677,26 @@ bool ProcessCmd(int fd, const PbDeviceDefinition& pbDevice, const PbOperation op
if (operation == ATTACH) { if (operation == ATTACH) {
if (map[id * UnitNum + unit]) { if (map[id * UnitNum + unit]) {
error << "Duplicate ID " << id; error << "Duplicate ID " << id << ", unit " << unit;
return ReturnStatus(fd, false, error); return ReturnStatus(fd, false, error);
} }
string filename = pbDevice.params(); string filename = pbDevice.params();
string ext; string ext;
int len = filename.length(); size_t separator = filename.rfind('.');
if (len > 4 && filename[len - 4] == '.') { if (separator != string::npos) {
ext = filename.substr(len - 3); ext = filename.substr(separator + 1);
} }
// Create a new device, based upon provided type or file extension // Create a new device, based upon the provided type or filename extension
device = device_factory.CreateDevice(type, filename, ext); device = device_factory.CreateDevice(type, filename, ext);
if (!device) { if (!device) {
return ReturnStatus(fd, false, "Invalid device type " + PbDeviceType_Name(type)); if (type == UNDEFINED) {
return ReturnStatus(fd, false, "Unknown image file extension '" + ext + "'");
}
else {
return ReturnStatus(fd, false, "Unknown device type " + PbDeviceType_Name(type));
}
} }
// If no filename was provided the media is considered removed // If no filename was provided the media is considered removed

View File

@ -427,6 +427,10 @@ int main(int argc, char* argv[])
case 't': case 't':
device->set_type(ParseType(optarg)); device->set_type(ParseType(optarg));
if (device->type() == UNDEFINED) {
cerr << "Error: Unknown device type '" << optarg << "'" << endl;
exit(EXIT_FAILURE);
}
break; break;
case 'g': case 'g':
@ -474,7 +478,7 @@ int main(int argc, char* argv[])
case 'p': case 'p':
port = atoi(optarg); port = atoi(optarg);
if (port <= 0 || port > 65535) { if (port <= 0 || port > 65535) {
cerr << "Invalid port " << optarg << ", port must be between 1 and 65535" << endl; cerr << "Error: Invalid port " << optarg << ", port must be between 1 and 65535" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
break; break;