-
Notifications
You must be signed in to change notification settings - Fork 58
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
catch Pyparsing exceptions #10
Open
arun3688
wants to merge
2
commits into
OpenModelica:master
Choose a base branch
from
arun3688:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
If you look into the code, the results of the compiler is returned not the
string we wanted to parse, because the Pyparsing does not give proper error
messages in case there are errors in the code
regards
arun
On Fri, Apr 29, 2016 at 2:37 PM, Christoph Buchner <notifications@github.com
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.
well, this is then just confusing nomenclature. this code snippet tries to parse a string called
result
. Let's consider this an input of this snippet, or "the string you want to parse". The string is parsed by passing it to a function calledparseString
. What you want to return is ananswer
, let's consider this an output of this snippet.Now, if
parseString
throws an exception, instead of reporting or returning the exception message, you returnresult
, i.e. the input of your snippet. You drop all notice of an error having occured, and return an unparsed input, instead of a parsed output.Btw, I don't know how familiar you are with python, but throwing exception is typically considered "proper error reporting", so the exceptions should contain valuable error information.
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 think you are not getting what i am saying, The result is output message obtained from the complier, (it can be both correct output and also error message). The Pyparsing in few cases does not give error messages, i hope you are using OMPython try this
omc.sendExpression("model a end a;")
output- (a,)
omc.sendExpression("model a end a2;")
The output should be a proper error message returned from the compiler and not just the pyparsing exception.
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.
Ah, so you are saying that if parseString throws an exception, you assume it's because
result
contains only a compiler error message, and not because of otherwise malformed compiler output, so you return the compiler error message instead of the parsedanswer
, right?Unfortunately, I'm on Python 3, so not using OMPython (yet).
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 agree that we should catch PyPArsingExceptions instead of all exceptions and should print its message.
Returning
result
is just fine. Basically from this function we want to return the result of the OMC API call done viasendExpression
.OMTypedParser.parseString
is used to format the result in a proper python type instead of just returning string type. So ifparseString
is successful return the formatted result i.e.,answer
otherwise just return theresult
.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.
No, returning
result
is not fine. How do you distinguish between a function returning a string and a function giving an error? If you wanted just the result, just do a call that does not expect the function to be possible to parse. Or add another OMPython call that tries to parse the string and otherwise always returns the result.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.
what about adding a parsed FLag in send Expression , so that when i want only unparsed result i can specify the flag to be false , like in this commit arun3688@ee3287a
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.
Just use a different python call for parsed=False. It should also fail when failing to parse, no questions asked.