Adding more robust checking for json parsing
This commit is contained in:
@@ -121,28 +121,42 @@ namespace daggy {
|
|||||||
|
|
||||||
// Grab the standard fields with defaults;
|
// Grab the standard fields with defaults;
|
||||||
if (spec.HasMember("isGenerator")) {
|
if (spec.HasMember("isGenerator")) {
|
||||||
|
if (! spec["isGenerator"].IsBool())
|
||||||
|
throw std::runtime_error("isGenerator must be a boolean value");
|
||||||
task.isGenerator = spec["isGenerator"].GetBool();
|
task.isGenerator = spec["isGenerator"].GetBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spec.HasMember("maxRetries")) {
|
if (spec.HasMember("maxRetries")) {
|
||||||
|
if (! spec["maxRetries"].IsInt())
|
||||||
|
throw std::runtime_error("maxRetries must be an integer");
|
||||||
task.maxRetries = spec["maxRetries"].GetInt();
|
task.maxRetries = spec["maxRetries"].GetInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spec.HasMember("retryIntervalSeconds")) {
|
if (spec.HasMember("retryIntervalSeconds")) {
|
||||||
|
if (! spec["retryIntervalSeconds"].IsInt())
|
||||||
|
throw std::runtime_error("retryIntervalSeconds must be an integer");
|
||||||
task.retryIntervalSeconds = spec["retryIntervalSeconds"].GetInt();
|
task.retryIntervalSeconds = spec["retryIntervalSeconds"].GetInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Children / parents
|
// Children / parents
|
||||||
if (spec.HasMember("children")) {
|
if (spec.HasMember("children")) {
|
||||||
|
if (! spec["children"].IsArray())
|
||||||
|
throw std::runtime_error("task.children must be specified as an array of strings");
|
||||||
const auto &specChildren = spec["children"].GetArray();
|
const auto &specChildren = spec["children"].GetArray();
|
||||||
for (size_t c = 0; c < specChildren.Size(); ++c) {
|
for (size_t c = 0; c < specChildren.Size(); ++c) {
|
||||||
|
if (! specChildren[c].IsString())
|
||||||
|
throw std::runtime_error("task.children must be specified as an array of strings");
|
||||||
task.children.insert(specChildren[c].GetString());
|
task.children.insert(specChildren[c].GetString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spec.HasMember("parents")) {
|
if (spec.HasMember("parents")) {
|
||||||
|
if (! spec["parents"].IsArray())
|
||||||
|
throw std::runtime_error("task.parents must be specified as an array of strings");
|
||||||
const auto &specParents = spec["parents"].GetArray();
|
const auto &specParents = spec["parents"].GetArray();
|
||||||
for (size_t c = 0; c < specParents.Size(); ++c) {
|
for (size_t c = 0; c < specParents.Size(); ++c) {
|
||||||
|
if (! specParents[c].IsString())
|
||||||
|
throw std::runtime_error("task.parents must be specified as an array of strings");
|
||||||
task.parents.insert(specParents[c].GetString());
|
task.parents.insert(specParents[c].GetString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,13 +168,16 @@ namespace daggy {
|
|||||||
for (auto it = params.MemberBegin(); it != params.MemberEnd(); ++it) {
|
for (auto it = params.MemberBegin(); it != params.MemberEnd(); ++it) {
|
||||||
if (!it->name.IsString())
|
if (!it->name.IsString())
|
||||||
throw std::runtime_error("job key must be a string.");
|
throw std::runtime_error("job key must be a string.");
|
||||||
|
auto name = it->name.GetString();
|
||||||
|
|
||||||
if (it->value.IsArray()) {
|
if (it->value.IsArray()) {
|
||||||
std::vector<std::string> values;
|
std::vector<std::string> values;
|
||||||
for (size_t i = 0; i < it->value.Size(); ++i) {
|
for (size_t i = 0; i < it->value.Size(); ++i) {
|
||||||
|
if (! it->value[i].IsString())
|
||||||
|
throw std::runtime_error(std::string{"All entries in job."} + name + " must be strings");
|
||||||
values.emplace_back(it->value[i].GetString());
|
values.emplace_back(it->value[i].GetString());
|
||||||
}
|
}
|
||||||
task.job.insert_or_assign(it->name.GetString(), values);
|
task.job.insert_or_assign(name, values);
|
||||||
}
|
}
|
||||||
else if (it->value.IsString()) {
|
else if (it->value.IsString()) {
|
||||||
task.job.insert_or_assign(it->name.GetString(),
|
task.job.insert_or_assign(it->name.GetString(),
|
||||||
|
|||||||
Reference in New Issue
Block a user