aws / aws-iot-device-sdk-python-v2

Next generation AWS IoT Client SDK for Python using the AWS Common Runtime
Apache License 2.0
409 stars 212 forks source link

Better error description when calling a subscribe on SubscribeToTopicRequest without a topic specified #247

Open clogwog opened 3 years ago

clogwog commented 3 years ago

Is your feature request related to a problem? Please describe. I made a mistake by subscribing to a topic but specifying a wrong data member as the topic

responserequest = SubscribeToTopicRequest()
responserequest.topic_name =  "$aws/things/mythingname/shadow/name/streamcontrol/update/delta"
g_shadow_handler = shadow_delta_handler()
g_delta_subscribe_operation = g_ipc_client.new_subscribe_to_topic(g_shadow_handler)
future = g_delta_subscribe_operation.activate(responserequest)
future.result()

notice my mistake by using topic_name instead of topic

because of the flexibility of python i didn't see any error when specifying topic_name which is not a member of the SubscribeToTopicRequest class.

The error i did see in the greengrass.log was :

2021-10-29T01:45:08.264Z https://forums.aws.amazon.com/ (Thread-6) software.amazon.awssdk.eventstreamrpc.ServiceOperationMappingContinuationHandler: Sending connect response for au.com.mtdata.smartdvr.gg_shadow_config. {}
2021-10-29T01:45:08.267Z https://forums.aws.amazon.com/ (Thread-6) com.aws.greengrass.ipc.common.ExceptionUtil: Unhandled exception in IPC. {}
java.lang.NullPointerException
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1690)
at com.aws.greengrass.builtin.services.pubsub.PubSubIPCEventStreamAgent.handleSubscribeToTopicRequest(PubSubIPCEventStreamAgent.java:160)
at com.aws.greengrass.builtin.services.pubsub.PubSubIPCEventStreamAgent.access$300(PubSubIPCEventStreamAgent.java:45)
at com.aws.greengrass.builtin.services.pubsub.PubSubIPCEventStreamAgent$SubscribeToTopicOperationHandler.lambda$handleRequest$1(PubSubIPCEventStreamAgent.java:237)
at com.aws.greengrass.ipc.common.ExceptionUtil.translateExceptions(ExceptionUtil.java:33)
at com.aws.greengrass.builtin.services.pubsub.PubSubIPCEventStreamAgent$SubscribeToTopicOperationHandler.handleRequest(PubSubIPCEventStreamAgent.java:230)
at com.aws.greengrass.builtin.services.pubsub.PubSubIPCEventStreamAgent$SubscribeToTopicOperationHandler.handleRequest(PubSubIPCEventStreamAgent.java:209)
at software.amazon.awssdk.eventstreamrpc.OperationContinuationHandler.onContinuationMessage(OperationContinuationHandler.java:271)
at software.amazon.awssdk.crt.eventstream.ServerConnectionContinuationHandler.onContinuationMessageShim(ServerConnectionContinuationHandler.java:53)

2021-10-29T01:45:08.270Z https://forums.aws.amazon.com/ (Thread-6) software.amazon.awssdk.eventstreamrpc.RpcServer: New connection code https://forums.aws.amazon.com/ for https://forums.aws.amazon.com/(2021-10-29T01:45:08.270133Z) - <null>. {}
2021-10-29T01:45:08.272Z https://forums.aws.amazon.com/ (Thread-6) software.amazon.awssdk.eventstreamrpc.ServiceOperationMappingContinuationHandler: aws.greengrass#GreengrassCoreIPC authenticated identity: au.com.mtdata.smartdvr.gg_shadow_config. {}

which is not very helpful to find and resolve the issue

Describe the solution you'd like When subscribing using SubscribeToTopicRequest and there is no topic specified, perhaps have a clear message saying "Can't subscribe as no topic has been specified"

Describe alternatives you've considered The alternative is to follow the API from the start.. which is fully on me

Additional context The original issue that lead to this issue being raised : https://forums.aws.amazon.com/thread.jspa?messageID=999711&#999711

jmklix commented 2 years ago

Thanks for pointing this out. This is something that we will look at improving in the future.