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

Improve error reporting when connnecting with a bad channel #1859

Merged
merged 3 commits into from
Feb 21, 2023

Conversation

plule-ansys
Copy link
Contributor

@plule-ansys plule-ansys commented Feb 16, 2023

Connecting PyMAPDL to a bad channel leads to an exception cascade instead of reporting the actual failure:

import grpc
from ansys.mapdl.core import Mapdl
bad_channel = grpc.insecure_channel("willnotwork")
mapdl = Mapdl(channel=bad_channel)

AttributeError: 'NoneType' object has no attribute 'pid'

Similarly, a bad channel with an interceptor also leads to an exception cascade:

import grpc
from ansys.mapdl.core import Mapdl
from grpc import UnaryUnaryClientInterceptor

class PassThru(UnaryUnaryClientInterceptor):
   def intercept_unary_unary(continuation, client_call_details, request):
     return continuation(client_call_details, request)

bad_channel_with_interceptor = grpc.intercept_channel(grpc.insecure_channel("willnotwork"), PassThru())
mapdl = Mapdl(channel=bad_channel_with_interceptor)

AttributeError: 'Channel' object has no attribute 'target'

This pull request adds a check of the presence of a PID before trying to get a status from it, and improves the _channel_str method to try to find nested targets. For both example, the error is now the expected:

ansys.mapdl.core.errors.MapdlConnectionError: Unable to connect to MAPDL gRPC instance at willnotwork.
Reached either maximum amount of connection attempts (5) or timeout (15 s).

@github-actions github-actions bot added the BUG Issue, problem or error in PyMAPDL label Feb 16, 2023
@github-actions
Copy link
Contributor

Please add one of the following labels to add this contribution to the Release Notes 👇

@codecov
Copy link

codecov bot commented Feb 17, 2023

Codecov Report

Merging #1859 (e49dd2f) into main (2d31773) will decrease coverage by 4.80%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1859      +/-   ##
==========================================
- Coverage   85.72%   80.93%   -4.80%     
==========================================
  Files          44       44              
  Lines        7840     7842       +2     
==========================================
- Hits         6721     6347     -374     
- Misses       1119     1495     +376     

Copy link
Collaborator

@germa89 germa89 left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution @plule-ansys !!

I happily approve. I just have some questions regarding implementation. Regards!

src/ansys/mapdl/core/mapdl_grpc.py Show resolved Hide resolved
src/ansys/mapdl/core/mapdl_grpc.py Show resolved Hide resolved
Copy link
Contributor

@clatapie clatapie left a comment

Choose a reason for hiding this comment

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

I agree with @germa89's comments. Apart from that, it looks good to me. 👍
Thank you @plule-ansys!

@germa89 germa89 merged commit d7dbe9a into main Feb 21, 2023
@germa89 germa89 deleted the fix/bad_channel_error branch February 21, 2023 10:26
@germa89
Copy link
Collaborator

germa89 commented Feb 21, 2023

Merged. Thank you @plule-ansys !! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Issue, problem or error in PyMAPDL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants