-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More helpful exception text for Registerbase #1080
More helpful exception text for Registerbase #1080
Conversation
I agree the error msg is terrible. I tried a stupid input file with With v2.9 the error is:
which we deemed cryptic. Now it is
which I would argue is far worse. Perhaps can be something like:
Plus, if XXX is in the ModuleMap:
|
ok, so the modifications could be
For the text I am going with your proposals |
Now the output is:
When the missing action is in the moduleMap or
when the missing action is not in the moduleMap I set up the exception also for the CLTool, for completion, since |
@@ -208,7 +227,9 @@ const Content & RegisterBase<Content>::get(const std::vector<void*> & images,con | |||
auto qualified_key=imageToString(*image) + ":" + key; | |||
if(m.count(qualified_key)>0) return m.find(qualified_key)->second->content; | |||
} | |||
plumed_assert(m.count(key)>0); | |||
if (m.count(key) == 0 ) { | |||
throw ExceptionRegisterError().setMissingKey(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Iximiel I think the standard way is to have a constructor with a std::string argument did you try and it didn't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set up the additional member because the string ctor (Exception.h:222)
explicit Exception(const std::string & msg):
Exception()
{
*this << msg;
}
calls operator <<
and that prepends a newline to the internal message if note
is set to true, that is its default value, so .what()
always starts with \n
.
I think that manipulating the exception like this is clearer and more flexible like I did in ActionRegister.cpp:49:
try{
...
} catch (PLMD::ExceptionRegisterError &e ) {
auto& actionName = e.getMissingKey();
e <<"Action \"" << actionName << "\" is not known.";
if (getModuleMap().count(actionName)>0) {
e << "\nAn Action named \""
<<actionName
<<"\" is available in module \""
<< getModuleMap().at(actionName)
<< "\".\nPlease consider installing PLUMED with that module enabled.";
}
}
In this way, I have this error about this "key", and I can react to the key in the catch block, separating the logic of getModuleMap()
from the logic of the register.
I use throw ExceptionRegisterError().setMissingKey(key);
three times, so moving the getModuleMapp()
logic in the catch block prevents me from repeating the code.
This should make the code more flexible because the throws
are in the RegisteBase and the exception could be thrown from an Action or CL register specialization.
Moreover, in this way, I do not need to remove the eventual stack trace that the ctor puts in msg
to get the key
If you are ok with this, I think I need to add at least a docstring to explain how to use this for eventual new registers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Iximiel @GiovanniBussi I think this is useful to merge, what is missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to add the docstring and then it is ready
Description
I was running some tests on some previous commit (where regtest/clusters/rt-dfg1/config had a wrong module prerequisites instead of
plumed_modules="adjmat clusters"
) and the exception text+++ assertion failed: m.count(key)>0
felt not helpful.I think that the text
+++ assertion failed: m.count(key)>0, Missing key is "KEYNAME"
feel a little more helpful.I think these few lines may help at least in doing a
git grep KEYNAME
in src or aplumed manual KEYNAME
to find at least which module has not been loaded.An maybe we can use #1063 for giving directly that info, I do not know if directly in the register or also in an ad-hoc cltool or in cltools/Manual.cpp
Target release
I would like my code to appear in release 2.10
Type of contribution
Copyright
COPYRIGHT
file with the correct license information. Code should be released under an open source license. I also used the commandcd src && ./header.sh mymodulename
in order to make sure the headers of the module are correct.Tests