@@ -757,6 +757,11 @@ namespace application
757757
758758 The method call in echo console for value="{ "bool":true }" would be:
759759 Method "{ \"bool\":true }"
760+
761+ Best practice: To avoid ambiguity when multiple services have methods with the same name, prefix the method with the service name.
762+ For example, if both GapCentral and GapPeripheral in Gap.proto have a RemoveAllBonds method, call the GapCentral version as:
763+ GapCentral.RemoveAllBonds
764+
760765 5. Primitive types mapping table:
761766 +-----------------+-----------------+-------------------------------------+
762767 | Proto Type | Token Type | Example Input |
@@ -923,6 +928,19 @@ namespace application
923928 {
924929 services::GlobalTracer ().Trace () << " Incorrect type at index " << error.index << " expected type " << error.correctType << " (contents after that position is " << line.substr (error.index ) << " )\n " ;
925930 }
931+ catch (ConsoleExceptions::AmbiguousMethod& error)
932+ {
933+ services::GlobalTracer ().Trace () << " Ambiguous method call: '" << error.methodName << " ' exists in multiple services: " ;
934+
935+ for (const auto & serviceName : error.serviceNames )
936+ {
937+ if (&serviceName != &error.serviceNames .front ())
938+ services::GlobalTracer ().Continue () << " , " ;
939+ services::GlobalTracer ().Continue () << serviceName;
940+ }
941+
942+ services::GlobalTracer ().Continue () << " \n Please specify the service name, e.g., " << error.serviceNames .front () << " ." << error.methodName << " \n " ;
943+ }
926944 catch (ConsoleExceptions::MethodNotFound& error)
927945 {
928946 services::GlobalTracer ().Trace () << " Method " ;
@@ -940,15 +958,29 @@ namespace application
940958
941959 std::pair<std::shared_ptr<const EchoService>, const EchoMethod&> Console::SearchMethod (MethodInvocation& methodInvocation) const
942960 {
961+ std::vector<std::pair<std::shared_ptr<const EchoService>, const EchoMethod*>> matchingMethods;
962+
943963 for (auto service : root.services )
944964 {
945965 if (methodInvocation.method .size () == 1 || methodInvocation.method .front () == service->name )
946966 for (auto & method : service->methods )
947967 if (method.name == methodInvocation.method .back ())
948- return std::pair<std::shared_ptr<const EchoService>, const EchoMethod&>(service, method);
968+ matchingMethods.emplace_back (std::make_pair (service, &method));
969+ }
970+
971+ if (matchingMethods.empty ())
972+ throw ConsoleExceptions::MethodNotFound{ methodInvocation.method };
973+
974+ if (methodInvocation.method .size () == 1 && matchingMethods.size () > 1 )
975+ {
976+ std::vector<std::string> serviceNames;
977+ for (const auto & [echoService, echoMethod] : matchingMethods)
978+ serviceNames.push_back (echoService->name );
979+
980+ throw ConsoleExceptions::AmbiguousMethod{ methodInvocation.method .back (), serviceNames };
949981 }
950982
951- throw ConsoleExceptions::MethodNotFound{ methodInvocation. method } ;
983+ return std::pair<std::shared_ptr< const EchoService>, const EchoMethod&>(matchingMethods[ 0 ]. first , *matchingMethods[ 0 ]. second ) ;
952984 }
953985
954986 Console::MethodInvocation::MethodInvocation (const std::string& line)
0 commit comments