Commit ab126be4 authored by Millian Poquet's avatar Millian Poquet
Browse files

[code] str->iset error log++ (fix gitlab #12)

parent 30a94499
......@@ -162,9 +162,9 @@ string MachineRange::to_string_elements(const string &sep) const
return boost::algorithm::join(machine_id_strings, sep);
}
MachineRange MachineRange::from_string_hyphen(const string &str,
const string &sep,
const string &joiner,
MachineRange MachineRange::from_string_hyphen(const string & str,
const string & sep,
const string & joiner,
const string & error_prefix)
{
(void) error_prefix; // Avoids a warning if assertions are ignored
......@@ -180,25 +180,39 @@ MachineRange MachineRange::from_string_hyphen(const string &str,
vector<string> interval_parts;
boost::split(interval_parts, part, boost::is_any_of(joiner), boost::token_compress_on);
xbt_assert(interval_parts.size() >= 1 && interval_parts.size() <= 2,
"%s: the MIDk '%s' should either be a single machine ID"
" (syntax: MID to represent the machine ID MID) or a closed interval (syntax: MIDa-MIDb to represent"
" the machine interval [MIDA,MIDb])", error_prefix.c_str(), part.c_str());
"%s: The part '%s' (from '%s') should either be a single machine ID "
"(syntax: MID to represent the machine ID) or a closed interval "
"(syntax: MIDa-MIDb to represent the machine interval [MIDA,MIDb])",
error_prefix.c_str(), part.c_str(), str.c_str());
if (interval_parts.size() == 1)
try
{
int machine_id = std::stoi(interval_parts[0]);
res.insert(machine_id);
if (interval_parts.size() == 1)
{
int machine_id = std::stoi(interval_parts[0]);
res.insert(machine_id);
}
else
{
int machineIDa = std::stoi(interval_parts[0]);
int machineIDb = std::stoi(interval_parts[1]);
xbt_assert(machineIDa <= machineIDb,
"%s: The part '%s' (from '%s') follows the MIDa-MIDb syntax. "
"However, the first value should be lesser than or equal to the second one",
error_prefix.c_str(), part.c_str(), str.c_str());
res.insert(MachineRange::ClosedInterval(machineIDa, machineIDb));
}
}
else
catch(const std::exception &)
{
int machineIDa = std::stoi(interval_parts[0]);
int machineIDb = std::stoi(interval_parts[1]);
xbt_assert(machineIDa <= machineIDb, "%s: the MIDk '%s' is composed of two"
" parts (1:%d and 2:%d) but the first value must be lesser than or equal to the second one",
error_prefix.c_str(), part.c_str(), machineIDa, machineIDb);
res.insert(MachineRange::ClosedInterval(machineIDa, machineIDb));
XBT_CRITICAL("%s: Could not read integers from part '%s' (from '%s'). "
"The part should either be a single machine ID "
"(syntax: MID to represent the machine ID) or a closed interval "
"(syntax: MIDa-MIDb to represent the machine interval [MIDA,MIDb])",
error_prefix.c_str(), part.c_str(), str.c_str());
xbt_abort();
}
}
......
......@@ -481,7 +481,7 @@ void JsonProtocolReader::handle_execute_job(int event_number,
xbt_assert(alloc_value.IsString(), "Invalid JSON message: the 'alloc' value in the 'data' value of event %d (EXECUTE_JOB) should be a string.", event_number);
string alloc = alloc_value.GetString();
message->allocation->machine_ids = MachineRange::from_string_hyphen(alloc, " ", "-", "Invalid JSON message: ");
message->allocation->machine_ids = MachineRange::from_string_hyphen(alloc, " ", "-", "Invalid JSON message received from the scheduler");
int nb_allocated_resources = message->allocation->machine_ids.size();
(void) nb_allocated_resources; // Avoids a warning if assertions are ignored
xbt_assert(nb_allocated_resources > 0, "Invalid JSON message: in event %d (EXECUTE_JOB): the number of allocated resources should be strictly positive (got %d).", event_number, nb_allocated_resources);
......@@ -612,7 +612,7 @@ void JsonProtocolReader::handle_set_resource_state(int event_number,
xbt_assert(resources_value.IsString(), "Invalid JSON message: the 'resources' value in the 'data' value of event %d (SET_RESOURCE_STATE) should be a string.", event_number);
string resources = resources_value.GetString();
message->machine_ids = MachineRange::from_string_hyphen(resources, " ", "-", "Invalid JSON message: ");
message->machine_ids = MachineRange::from_string_hyphen(resources, " ", "-", "Invalid JSON message received from the scheduler");
int nb_allocated_resources = message->machine_ids.size();
(void) nb_allocated_resources; // Avoids a warning if assertions are ignored
xbt_assert(nb_allocated_resources > 0, "Invalid JSON message: in event %d (SET_RESOURCE_STATE): the number of allocated resources should be strictly positive (got %d).", event_number, nb_allocated_resources);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment