Data2Dynamics / d2d

a modeling environment tailored to parameter estimation in dynamical systems
https://github.com/Data2Dynamics/d2d
57 stars 29 forks source link

Error message in argSwitch #101

Closed plakrisenko closed 6 years ago

plakrisenko commented 6 years ago

For example, line 40: error( sprintf( 'Invalid switch argument was provided "%s". Valid arguments are %s\n', varargin{1}{a}, sprintf( '''%s'' ', switches{:} ) ) ); It is assumed here that varargin{1}{a} will be a string, so when it's not the message isn't correct. For example, for the following call of the function arImportSBML: "ms = arImportSBML('BIOMD0000000379', 100)", the error message is: "Error using argSwitch (line 40) Invalid switch argument was provided "d". Valid arguments are 'tend' 'overwrite' 'keepcompartments' 'compartmentbyname'"

I have found the following discussion on the topic on stackoverflow: https://stackoverflow.com/questions/12799161/is-there-a-matlab-function-to-convert-any-data-structure-to-a-string. Rody Oldenhuis has written a function that can be used to fix this issue: https://www.mathworks.com/matlabcentral/fileexchange/38566-string-representation-of-any-data-type. I don't know if it's the best solution, but this function seems better to me than accepted answer in this thread.

JoepVanlier commented 6 years ago

Does this refer to the previous issue you opened? If this is the case, see the reply to your previous issue, namely that you specified one argument too many. I made the error that argSwitch throws a little bit more descriptive and cast it to a string the regular way.

plakrisenko commented 6 years ago

No, it's a different issue. It is assumed here that varargin{1}{a} will be a string, so when it's not the message is incorrect. If, for example, varargin{1}{a} = 100 error message is not "Invalid switch argument was provided "100".", but "Invalid switch argument was provided "d"." So, 100 is interpreted as ACII code of "d" or something like that.

JoepVanlier commented 6 years ago

Somehow I had missed this second reply, sorry.

Yes. You are correct that this wasn't the intended result. The function in the stackexchange answer is a bit overkill for the situation I think. I've added error handling where a passed array is shown, and other datatypes are shown by class instead in commit 539fe6f728fce41b96562caadb729c06c3061bba .

Thanks for the report! :+1: