You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by dm...@apache.org on 2023/09/27 09:02:03 UTC

[trafficserver] branch master updated: CID-1508880: Re-work function to avoid dead-code. (#10475)

This is an automated email from the ASF dual-hosted git repository.

dmeden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 1f99445892 CID-1508880: Re-work function to avoid dead-code. (#10475)
1f99445892 is described below

commit 1f99445892de7a40f7d28393eac5fe17d287b241
Author: Damian Meden <dm...@apache.org>
AuthorDate: Wed Sep 27 11:01:56 2023 +0200

    CID-1508880: Re-work function to avoid dead-code. (#10475)
---
 include/shared/rpc/RPCClient.h | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/include/shared/rpc/RPCClient.h b/include/shared/rpc/RPCClient.h
index 4336dd8cc3..d3a85fef0b 100644
--- a/include/shared/rpc/RPCClient.h
+++ b/include/shared/rpc/RPCClient.h
@@ -52,7 +52,7 @@ public:
   std::string
   invoke(std::string_view req)
   {
-    std::string text; // for error messages.
+    std::string err_text; // for error messages.
     std::unique_ptr<char[]> buf(new char[BUFFER_SIZE]);
     swoc::FixedBufferWriter bw{buf.get(), BUFFER_SIZE};
     try {
@@ -64,23 +64,22 @@ public:
           _client.disconnect();
           return {bw.data(), bw.size()};
         }
-        case IPCSocketClient::ReadStatus::BUFFER_FULL: {
-          throw std::runtime_error(
-            swoc::bwprint(text, "Buffer full, not enough space to read the response. Buffer size: {}", BUFFER_SIZE));
-        } break;
+        case IPCSocketClient::ReadStatus::BUFFER_FULL:
+          swoc::bwprint(err_text, "Buffer full, not enough space to read the response. Buffer size: {}", BUFFER_SIZE);
+          break;
         default:
-          throw std::runtime_error("Something happened, we can't read the response");
+          err_text = "Something happened, we can't read the response";
           break;
         }
       } else {
-        throw std::runtime_error(swoc::bwprint(text, "Node seems not available: {}", std ::strerror(errno)));
+        swoc::bwprint(err_text, "Node seems not available: {}", std ::strerror(errno));
       }
     } catch (std::exception const &ex) {
-      _client.disconnect();
-      throw std::runtime_error(swoc::bwprint(text, "RPC Node Error: {}", ex.what()));
+      swoc::bwprint(err_text, "RPC Node Error: {}", ex.what());
     }
-
-    return {};
+    _client.disconnect();
+    // If we've got this far, then there must be an error to report back.
+    throw std::runtime_error(err_text);
   }
 
   /// @brief Invoke the rpc node passing the JSONRPC objects.