Improve error message for using protected keywords
Reported by @zhang_h:
An input like:
ring: Cyclotron, TYPE="RING", ...;
will generate an error:
Error>
Error> *** User error detected by function "OpalData::define()"
Error> You cannot replace the object "RING".
Error> You cannot replace the object "RING".
This is because ring
is a protected keyword and can't be used as an object name. However, from the user perspective this seems not very clear.
The error message comes from OpalData.cpp:
if (oldObject->isBuiltin() || ! oldObject->canReplaceBy(newObject)) {
throw OpalException("OpalData::define()",
"You cannot replace the object \"" + name + "\".");
} else {
I propose to make a distinction between the two cases and change it to:
if (oldObject->isBuiltin()) {
throw OpalException("OpalData::define()",
"The keyword \"" + name + "\" is protected and can't be used to name an object.");
else if (! oldObject->canReplaceBy(newObject)) {
throw OpalException("OpalData::define()",
"You cannot replace the already defined object \"" + name + "\".");
} // else not needed
Also it might be good not to have "name" in uppercase letters if the user writes it in lowercase, but I couldn't quickly find out where this happens.