Skip to content

Fix invalid session bad error description#2181

Draft
zoechanzy wants to merge 2 commits into
ni:masterfrom
zoechanzy:users/zchan/fix-invalid-session-error-description
Draft

Fix invalid session bad error description#2181
zoechanzy wants to merge 2 commits into
ni:masterfrom
zoechanzy:users/zchan/fix-invalid-session-error-description

Conversation

@zoechanzy

Copy link
Copy Markdown
  • This contribution adheres to CONTRIBUTING.md.

  • I've updated CHANGELOG.md if applicable.

  • I've added tests applicable for this pull request

What does this Pull Request accomplish?

  • Fixes get_error_description returning "Failed to retrieve error description." when the session is invalid but get_error returns a code that doesn't match the original error_code.
    • reset the session handle (set_session_handle()) and retries if first error_message(error_code) with the current session handle fails.
    • Updated the mako template and regenerated the affected drivers (nidcpower, nidigital, nidmm, nifake, nifgen, niscope, niswitch).
    • Added nifake unit test to verify the session-handle reset path calls error_message again with vi=0

List issues fixed by this Pull Request below, if any.

What testing has been done?

  • Unit tests and flake8 passed.

@codecov-commenter

codecov-commenter commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.65%. Comparing base (ab52ec6) to head (ab14a93).

Files with missing lines Patch % Lines
...erated/nidcpower/nidcpower/_library_interpreter.py 0.00% 7 Missing ⚠️
...erated/nidigital/nidigital/_library_interpreter.py 0.00% 7 Missing ⚠️
generated/nidmm/nidmm/_library_interpreter.py 0.00% 7 Missing ⚠️
generated/nifgen/nifgen/_library_interpreter.py 0.00% 7 Missing ⚠️
generated/niscope/niscope/_library_interpreter.py 0.00% 7 Missing ⚠️
...enerated/niswitch/niswitch/_library_interpreter.py 0.00% 7 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2181      +/-   ##
==========================================
- Coverage   89.85%   89.65%   -0.20%     
==========================================
  Files          73       73              
  Lines       19006    19048      +42     
==========================================
+ Hits        17077    17078       +1     
- Misses       1929     1970      +41     
Flag Coverage Δ
codegenunittests 84.90% <ø> (ø)
nidcpowersystemtests 94.38% <0.00%> (-0.23%) ⬇️
nidcpowerunittests 89.53% <ø> (ø)
nidigitalsystemtests 92.02% <0.00%> (-0.24%) ⬇️
nidigitalunittests 68.44% <ø> (ø)
nidmmsystemtests 92.29% <0.00%> (-0.44%) ⬇️
nifakeunittests 86.01% <ø> (ø)
nifgensystemtests 94.32% <0.00%> (-0.30%) ⬇️
nimodinstsystemtests 73.85% <ø> (ø)
nimodinstunittests 94.20% <ø> (ø)
nirfsgsystemtests 81.12% <ø> (ø)
niscopesystemtests 92.66% <0.00%> (-0.28%) ⬇️
niscopeunittests 43.20% <ø> (ø)
nisesystemtests 91.50% <ø> (ø)
niswitchsystemtests 81.56% <0.00%> (-0.48%) ⬇️
nitclksystemtests 94.87% <ø> (ø)
nitclkunittests 98.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...erated/nidcpower/nidcpower/_library_interpreter.py 91.25% <0.00%> (-1.00%) ⬇️
...erated/nidigital/nidigital/_library_interpreter.py 89.66% <0.00%> (-0.72%) ⬇️
generated/nidmm/nidmm/_library_interpreter.py 88.74% <0.00%> (-1.37%) ⬇️
generated/nifgen/nifgen/_library_interpreter.py 95.54% <0.00%> (-1.04%) ⬇️
generated/niscope/niscope/_library_interpreter.py 92.57% <0.00%> (-1.09%) ⬇️
...enerated/niswitch/niswitch/_library_interpreter.py 73.62% <0.00%> (-1.45%) ⬇️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab52ec6...ab14a93. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zoechanzy zoechanzy force-pushed the users/zchan/fix-invalid-session-error-description branch from 3c6da41 to ab14a93 Compare June 29, 2026 14:42
Comment on lines +110 to +113
error_string = self.error_message(error_code)
return error_string
except errors.Error:
pass

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible that the session is valid but the returned_error_code unequal to error_code

If this happens, then something likely went wrong retrieving the error message. I'm not sure calling error_message instead of get_error_description is going to change anything in that case.

Comment on lines +121 to 122
self.set_session_handle()
error_string = self.error_message(error_code)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you add the other error_message call to protect against resetting the session handle in instances where the session is valid but we fail to retrieve the error message?

@zoechanzy zoechanzy Jun 30, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My current approach is wrong because it reset valid session. Adding error_message call will not help to protect against it because it is unable to know error_message throw exception because of invalid session or any other internal error. Maybe I should compare its error code directly with the invalid error session code?

@ni-jfitzger

Copy link
Copy Markdown
Collaborator

FYI @zoechanzy , our Linux VM is currently in bad shape, so Linux System tests are going to fail. We hope to have it resolved in the next week or two.

pass

try:
'''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, it's weird that these are multi-line string literals instead of comments. They are not in a position where they will be interpreted as docstrings.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that struck me as odd, too.
Apparently the Python interpreter will evaluate it as a string and then discard it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will.

BTW it's legal to write a docstring inside an init method, e.g. https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html

self.attr5 = None
"""str: Docstring *after* attribute, with type specified."""

But that's not what's being done here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants