Skip to content
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

throw error when variable not found #36

Closed
Mathadon opened this issue Jan 11, 2021 · 12 comments
Closed

throw error when variable not found #36

Mathadon opened this issue Jan 11, 2021 · 12 comments

Comments

@Mathadon
Copy link

Mathadon commented Jan 11, 2021

The line

ModelicaFormatMessage("Cannot find numeric value \"%s\" in file \"%s\"\n",
throws a message when a double cannot be found in a json file. It seems that the function then returns 0 as a default for that variable. When this message is overlooked by the user, it can result in completely wrong results that may go unnoticed. I would suggest to use ModelicaFormatError instead of ModelicaFormatMessage, or at least provide this as an optional flag. Note that for arrays an error is already thrown:
ModelicaFormatError("Cannot find array value \"%s\" in file \"%s\"\n",

@tbeu
Copy link
Contributor

tbeu commented Jan 11, 2021

That was changed to ModelicaFormatMessage by purpose for #21 in the lack of any better ideas, see especially #21 (comment). There is a Boolean output argument signaling if a scalar variable is found or not.

@tbeu
Copy link
Contributor

tbeu commented Jan 11, 2021

Reading my old commit message of bde9869 again I might change the message to ModelicaFormatWarning though.

@Mathadon
Copy link
Author

Mathadon commented Jan 11, 2021

In ExternData.Functions.JSON.getReal there could be an optional input generateError with default false? And based on that value you could decide whether to throw an error or a message (preferably warning, indeed).

@tbeu
Copy link
Contributor

tbeu commented Jan 11, 2021

You can workaround this use case by checking the output argument exist of function ExternData.Functions.JSON.getReal and call Modelica.Utilities.Streams.error if it is set to false.

@Mathadon
Copy link
Author

That indeed seems to be a valid workaround, but it is not that elegant (requires multiple lines of Modelica code). Is there something wrong with my suggestion?

@tbeu
Copy link
Contributor

tbeu commented Jan 11, 2021

No, nothing wrong, except that I'd make it an enumertaion argument with values "No message", "Debug message", "Warning message" and "Error message". The other point is that it will require quite some time to do it in a consistent way for all functions provided by ExternData.

@Mathadon
Copy link
Author

Let's see if I can help out.. If you can make a prototype implementation then I can replicate it for all JSON functions?

@tbeu
Copy link
Contributor

tbeu commented Jan 11, 2021

It is not only JSON, but let me think about it.

@Mathadon
Copy link
Author

Mathadon commented Jan 11, 2021

I figured, but I rather not spend 10h on it either 😅 If the JSON ends up not being too much work then I might do all of them, but no promises there.

@Mathadon
Copy link
Author

Any update on this? :)

@tbeu
Copy link
Contributor

tbeu commented Feb 27, 2021

I am surprised that the proposed workaround did not work out for you. Nevertheless, the diagnostic behaviour for missing data is a configuration parameter now.

@Mathadon
Copy link
Author

Mathadon commented Mar 1, 2021

This works great, thanks a lot!

overtaker added a commit that referenced this issue Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants