-
Notifications
You must be signed in to change notification settings - Fork 104
Fix the python session to return correct error message when invalid session for MI drivers #2181
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
base: master
Are you sure you want to change the base?
Changes from all commits
82373f8
ab14a93
5788750
4b16c37
d239d81
dfb69f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,15 +104,30 @@ def get_error_description(self, error_code): | |
| pass | ||
|
|
||
| try: | ||
| ''' | ||
| It is expected for get_error to raise when the session is invalid | ||
| (IVI spec requires GetError to fail). | ||
| Use error_message instead. It doesn't require a session. | ||
| ''' | ||
| # get_error reads the session's error queue, which may have been overwritten, | ||
| # causing it to return a mismatched error code. error_message takes the error | ||
| # code directly as a parameter and looks up its description without reading the | ||
| # queue, it will return the description for the specific error code. | ||
| # Use error_message in current session before the handle reset in the next block. | ||
|
|
||
| error_string = self.error_message(error_code) | ||
| return error_string | ||
| except errors.Error: | ||
| pass | ||
|
|
||
| save_vi = self.get_session_handle() | ||
| try: | ||
| # It is expected for get_error to raise when the session is invalid | ||
| # (IVI spec requires GetError to fail). | ||
| # Use error_message instead. It doesn't require a session. | ||
|
|
||
| self.set_session_handle() | ||
| error_string = self.error_message(error_code) | ||
|
Comment on lines
+124
to
125
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you add the other
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the scenario is valid session but failed to retrieve error message, it will enter third try block. Resetting the session will not affect its error_code so it will flow into the error_string = self.error_message(error_code) as well. It will still fail to retrieve the error message since the error_code is unchanged. So, it will raise execption and return "Failed to retrieve error description" If the scenario is invalid session, it will reset the session in third try block and self.error_message(error_code) will not raise execption because session is set to 0 already. So, it will return correct "The session handle is invalid" message.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure that's true. If you believe we could enter the third try block and reset the session when the session is valid and we fail to retrieve the error message, then you shouldn't be resetting the session. Failure to retrieve an error message does not justify leaking a valid session handle.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I tested with :
Since the real driver does not raise errors.Error from error_message() on a valid session either, I used a mock to cover the except errors.Error in second try block and third try block. It returns "Failed to retrieve error description."
I will update code to save the session handle before resetting it and restore it afterward to avoid leaking a valid session handle. We cannot selectively restore only valid sessions because we can only determine if a session handle is valid by calling a C driver function and observe whether it succeeds or fails. |
||
| return error_string | ||
| except errors.Error: | ||
| pass | ||
| finally: | ||
| self.set_session_handle(save_vi) | ||
| return "Failed to retrieve error description." | ||
|
|
||
| def abort(self, channel_name): # noqa: N802 | ||
|
|
||
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 this happens, then something likely went wrong retrieving the error message. I'm not sure calling
error_messageinstead ofget_error_descriptionis going to change anything in that case.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.
Calling get_error_description again might cause infinite loop.
Uh oh!
There was an error while loading. Please reload this page.
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, I wasn't suggesting that we call
get_error_descriptionagain. I'm merely trying to think about what behavior we'll see if this new section of code executes.Oh, i see. Sorry, I meant
get_error, notget_error_description.Uh oh!
There was an error while loading. Please reload this page.
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 also find this comment a bit confusing....
What I understand is
get_errorreads what is currently in the session, if it is overwritten or cleared it could still successfully run but will return mismatched error code.So this try block is to check the
error_messagein the current session first before proceed to theset_session_handlein the next try block.Uh oh!
There was an error while loading. Please reload this page.
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.
How about wording the comment to be like this?