Skip to content

Commit

Permalink
Add useful errors for mis-formatted or mis-read JSON files
Browse files Browse the repository at this point in the history
  • Loading branch information
GiudGiud committed Sep 25, 2023
1 parent 750d976 commit 11e380b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions framework/src/userobjects/JSONFileReader.C
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,22 @@ JSONFileReader::getVector(const std::vector<std::string> & vector_keys,
{
if (key_index == vector_keys.size() - 1)
{
const auto num_items = (*current_node).size();
if (!current_node->is_array())
mooseError("Cannot retrieve a vector from JSON node",
*current_node,
"obtained with last key",
vector_keys[key_index]);
const auto num_items = current_node->size();
vector_to_fill.resize(num_items);
for (const auto & index : make_range(num_items))
vector_to_fill[index] = getReal((*current_node)[index]);
break;
return;
}
if (current_node->is_array())
mooseError("Cannot obtain nested JSON item with key",
vector_keys[key_index + 1],
"because the current item is an array:",
*current_node);
current_node = &(*current_node)[vector_keys[key_index + 1]];
}
}
Expand Down

0 comments on commit 11e380b

Please sign in to comment.