Giter Site home page Giter Site logo

Comments (6)

ohDaddyPlease avatar ohDaddyPlease commented on May 30, 2024 1

I think you need to create issue in https://github.com/memphisdev/memphis.py

from memphis.py.

yanivbh1 avatar yanivbh1 commented on May 30, 2024 1

Adding @shay23b to the rescue

from memphis.py.

Adarsh-jaiss avatar Adarsh-jaiss commented on May 30, 2024

Hey @yanivbh1 , i would love to work on this issue. Can you please tell me the file in which i should make the changes to make things work, because I have looked upon the code base, but i am unable to understand where this error message has been written.

from memphis.py.

shay23b avatar shay23b commented on May 30, 2024

Hi @Adarsh-jaiss ,
There are a few functions that raise "Unsupported message type" error in the producer.py file, in this case it returns from the "validate_protobuf" function

from memphis.py.

Adarsh-jaiss avatar Adarsh-jaiss commented on May 30, 2024

Hey @shay23b, @yanivbh1 , I tried to understand the bug and took help from an AI model and it suggested these changes in the "validate_protobuf" function :

In the updated code:

  • We added an additional elif condition to check if the message is of type dict. Previously, only bytearray and objects with SerializeToString method were supported. This will allow us to handle protobuf dictionaries as well.

  • In the else block, we raise a MemphisSchemaError with a more descriptive error message including the type of the unsupported message type.

By making these changes, the code will provide a clearer error message when encountering an unsupported message type. Additionally, it will be able to handle protobuf dictionaries as well.

Here's the updated code :

def validate_protobuf(self, message):
    proto_msg = self.connection.proto_msgs[self.internal_station_name]
    msg_to_send = ""

    try:
        if isinstance(message, bytearray):
            msg_to_send = bytes(message)
            try:
                proto_msg.ParseFromString(msg_to_send)
                proto_msg.SerializeToString()
                msg_to_send = msg_to_send.decode("utf-8")
            except Exception as e:
                if "parsing message" in str(e):
                    e = "Invalid message format, expecting protobuf"
                raise MemphisSchemaError(str(e))
            return message
        elif hasattr(message, "SerializeToString"):
            msg_to_send = message.SerializeToString()
            proto_msg.ParseFromString(msg_to_send)
            proto_msg.SerializeToString()
            try:
                proto_msg.ParseFromString(msg_to_send)
                proto_msg.SerializeToString()
            except Exception as e:
                if "parsing message" in str(e):
                    e = "Error parsing protobuf message"
                raise MemphisSchemaError(str(e))
            return msg_to_send
        elif isinstance(message, dict):
            try:
                protobuf_json_format.ParseDict(message, proto_msg)
                msg_to_send = proto_msg.SerializeToString()
                return msg_to_send
            except Exception as e:
                raise MemphisSchemaError(str(e))
        else:
            raise MemphisSchemaError("Unsupported message type: {}".format(type(message).__name__))

    except Exception as e:
        raise MemphisSchemaError("Schema validation has failed: " + str(e))

Kindly review this! @shay23b

from memphis.py.

shay23b avatar shay23b commented on May 30, 2024

Hi @Adarsh-jaiss,
Sorry for the delay
So regarding the first point - dict already exists as a type that can be passed so it is not needed to add
And regarding the second one - it is not enough to just say what type is not supported, it would be better to describe what the user can do in order to fix his problem - so for example add the supported types to the error

If you will be working on this issue please let us know and open a PR when you're done.
This is how to contribute:
https://github.com/memphisdev/memphis.py/blob/master/CONTRIBUTING.md

from memphis.py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.