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

Problem decoding response from invalid get on v23.X #2023

Closed
germa89 opened this issue Apr 25, 2023 · 2 comments
Closed

Problem decoding response from invalid get on v23.X #2023

germa89 opened this issue Apr 25, 2023 · 2 comments

Comments

@germa89
Copy link
Collaborator

germa89 commented Apr 25, 2023

ERROR    grpc._common:_common.py:92 Exception deserializing message!
Traceback (most recent call last):
  File "/Users/german.ayuso/pymapdl/.venv_macos/lib/python3.11/site-packages/grpc/_common.py", line 90, in _transform
    return transformer(message)
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/german.ayuso/pymapdl/.venv_macos/lib/python3.11/site-packages/google/protobuf/internal/python_message.py", line 801, in FromString
    message.MergeFromString(s)
  File "/Users/german.ayuso/pymapdl/.venv_macos/lib/python3.11/site-packages/google/protobuf/internal/python_message.py", line 1128, in MergeFromString
    if self._InternalParse(serialized, 0, length) != length:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/german.ayuso/pymapdl/.venv_macos/lib/python3.11/site-packages/google/protobuf/internal/python_message.py", line 1195, in InternalParse
    pos = field_decoder(buffer, new_pos, end, self, field_dict)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/german.ayuso/pymapdl/.venv_macos/lib/python3.11/site-packages/google/protobuf/internal/decoder.py", line 591, in DecodeField
    field_dict[key] = _ConvertToUnicode(buffer[pos:new_pos])
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/german.ayuso/pymapdl/.venv_macos/lib/python3.11/site-packages/google/protobuf/internal/decoder.py", line 553, in _ConvertToUnicode
    value = str(byte_str, 'utf-8')
            ^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa6 in position 184: 'utf-8' codec can't decode byte 0xa6 in position 184: invalid start byte in field: ansys.api.mapdl.v0.CmdResponse.response
============================================================== PyMAPDL Pytest short summary ===============================================================
[FAILED] test_invalid_get[False] - E           ansys.mapdl.core.errors.MapdlExitedError: MAPDL server connection terminated
@germa89
Copy link
Collaborator Author

germa89 commented Jul 14, 2023

Summary

Situation

This due to an MAPDL bug where an invalid field 5 or more returns a weird message:

 BEGIN:
*get,par,active,0,set


 *** WARNING ***
 *MSG ERROR. Incoming message is longer than 10 lines.
 Trying to process message:
 Bad field 6 ( ) for *GET entity ACTIVE and item=SET.                    
  Line=                                                                  
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         

 *** ERROR ***                           CP =       0.572   TIME= 10:25:39
 Bad field 6 ( ) for *GET entity ACTIVE and item=SET.                    
  Line=                                                                  
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         

 *GET  PAR       FROM  ACTI  ITEM=SET        VALUE=  0.00000000 

This bug gets rendered in the gRPC differently (probably because of the write to the file using /OUTPUT):


 /OUTPUT FILE= anstmp


 *** WARNING ***
 *MSG ERROR. Incoming message is longer than 10 lines.
 Trying to process message:
 Bad field 6 ( INVA ) for *GET entity ACTIVE and item=SET.               
  Line= ��Qi+                                                           
                                                                         
 ��Qi+                                                                  
                                                                         
 ��6�+                                                                  
                                                                         
 $$ji+                                                                  
                                                                         
                                                                         

 *** ERROR ***                           CP =       5.660   TIME= 10:41:18
 Bad field 6 ( INVA ) for *GET entity ACTIVE and item=SET.               
  Line= ��Qi+                                                           
                                                                         
 ��Qi+                                                                  
                                                                         
 ��6�+                                                                  
                                                                         
 $$ji+                                                                  
                                                                         
                                                                         

 /OUTPUT FILE= anstmp

Screenshot for completion:
image

These weird characters provoke the error when parsing the message:

=================================== FAILURES ===================================
_______________________________ test_invalid_get _______________________________

mapdl = <ansys.mapdl.core.mapdl_grpc.MapdlGrpc object at 0x7fc8bf26fd30>

    def test_invalid_get(mapdl):
        with pytest.raises((MapdlRuntimeError, MapdlCommandIgnoredError)):
>           mapdl.get_value("ACTIVE", item1="SET", it1num="invalid")

tests/test_grpc.py:116: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/ansys/mapdl/core/mapdl.py:2434: in get_value
    return self._get(
/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/ansys/mapdl/core/errors.py:153: in wrapper
    out = func(*args, **kwargs)
/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/ansys/mapdl/core/mapdl_grpc.py:2016: in _get
    out = self.run("*GET,__temp__," + cmd)
/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/ansys/mapdl/core/mapdl.py:3062: in run
    text = self._run(command, verbose=verbose, mute=mute)
/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/ansys/mapdl/core/mapdl_grpc.py:930: in _run
    response = self._send_command(cmd, mute=mute)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<ansys.mapdl.core.mapdl_grpc.MapdlGrpc object at 0x7fc8bf26fd30>, '*GET,__temp__,ACTIVE,,SET,invalid,,,, , ,')
kwargs = {'mute': False}, old_handler = <function handler at 0x7fc8c522edc0>
class_name = 'MapdlGrpc'
mapdl = <ansys.mapdl.core.mapdl_grpc.MapdlGrpc object at 0x7fc8bf26fd30>

    @wraps(func)
    def wrapper(*args, **kwargs):
        """Capture gRPC exceptions and KeyboardInterrupt"""
    
        # capture KeyboardInterrupt
        old_handler = None
        if threading.current_thread().__class__.__name__ == "_MainThread":
            if threading.current_thread().is_alive():
                old_handler = signal.signal(signal.SIGINT, handler)
    
        # Capture gRPC exceptions
        try:
            out = func(*args, **kwargs)
        except (_InactiveRpcError, _MultiThreadedRendezvous) as error:
            # can't use isinstance here due to circular imports
            try:
                class_name = args[0].__class__.__name__
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/grpc/_common.py", line 90, in _transform
    return transformer(message)
google.protobuf.message.DecodeError: Error parsing message with type 'ansys.api.mapdl.v0.CmdResponse'
----------------------------- Captured stderr call -----------------------------
[libprotobuf ERROR google/protobuf/wire_format_lite.cc:618] String field 'ansys.api.mapdl.v0.CmdResponse.response' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes. 
------------------------------ Captured log call -------------------------------
ERROR    grpc._common:_common.py:92 Exception deserializing message!
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/grpc/_common.py", line 90, in _transform
    return transformer(message)
google.protobuf.message.DecodeError: Error parsing message with type 'ansys.api.mapdl.v0.CmdResponse'
----------------------------- Captured stderr call -----------------------------
[libprotobuf ERROR google/protobuf/wire_format_lite.cc:618] String field 'ansys.api.mapdl.v0.CmdResponse.response' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes. 
------------------------------ Captured log call -------------------------------
ERROR    grpc._common:_common.py:92 Exception deserializing message!
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/grpc/_common.py", line 90, in _transform
    return transformer(message)
google.protobuf.message.DecodeError: Error parsing message with type 'ansys.api.mapdl.v0.CmdResponse'
----------------------------- Captured stderr call -----------------------------
[libprotobuf ERROR google/protobuf/wire_format_lite.cc:618] String field 'ansys.api.mapdl.v0.CmdResponse.response' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes. 
------------------------------ Captured log call -------------------------------
ERROR    grpc._common:_common.py:92 Exception deserializing message!
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.17/x64/lib/python3.9/site-packages/grpc/_common.py", line 90, in _transform
    return transformer(message)
google.protobuf.message.DecodeError: Error parsing message with type 'ansys.api.mapdl.v0.CmdResponse'

The error is later confirmed by some server side output:

[libprotobuf ERROR /home/staff/kkripa/tfsagent/_work/20/b/.conan/data/protobuf/3.10.1.3/thirdparty/stable/build/2a45a8e4e8f3a96579715eed8e14250652eeb4d4/protobuf/src/google/protobuf/wire_format_lite.cc:578] String field 'ansys.api.mapdl.v0.CmdResponse.response' contains invalid UTF-8 data when serializing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes. 

Approach

The approach now is to file a bug with the MAPDL team and mark the test as expected to fail. Also add another test which fail without that bug (invalid field less than 5)

This is implemented in the PR we discovered #1912

@germa89
Copy link
Collaborator Author

germa89 commented Sep 18, 2023

We can close this issue, because this needs to be addressed in the MAPDL team (and I think it has been) and we have the tests in place.

@germa89 germa89 closed this as completed Sep 18, 2023
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

No branches or pull requests

1 participant