This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new d60431d9d68 fix cpp client exception (#16284)
d60431d9d68 is described below
commit d60431d9d68b95014174541318e09f4ec37fdbf0
Author: Hongzhi Gao <[email protected]>
AuthorDate: Wed Aug 27 20:34:36 2025 +0800
fix cpp client exception (#16284)
* fix cpp client exception
* fix cpp client exception
* fix SessionBuilder.h
---
example/client-cpp-example/pom.xml | 4 ++++
example/client-cpp-example/src/CMakeLists.txt | 5 ++++-
.../client-cpp-example/src}/MultiSvrNodeClient.cpp | 0
iotdb-client/client-cpp/src/main/NodesSupplier.cpp | 4 +++-
iotdb-client/client-cpp/src/main/Session.cpp | 6 ++++--
iotdb-client/client-cpp/src/main/SessionBuilder.h | 2 +-
iotdb-client/client-cpp/src/test/cpp/sessionIT.cpp | 13 +++++++++++++
7 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/example/client-cpp-example/pom.xml
b/example/client-cpp-example/pom.xml
index 9dbccb1cb8d..11d794f082c 100644
--- a/example/client-cpp-example/pom.xml
+++ b/example/client-cpp-example/pom.xml
@@ -64,6 +64,10 @@
<sourceFile>${project.basedir}/src/TableModelSessionExample.cpp</sourceFile>
<destinationFile>${project.build.directory}/TableModelSessionExample.cpp</destinationFile>
</fileSet>
+ <fileSet>
+
<sourceFile>${project.basedir}/src/MultiSvrNodeClient.cpp</sourceFile>
+
<destinationFile>${project.build.directory}/MultiSvrNodeClient.cpp</destinationFile>
+ </fileSet>
<fileSet>
<sourceFile>${project.basedir}/src/CMakeLists.txt</sourceFile>
<destinationFile>${project.build.directory}/CMakeLists.txt</destinationFile>
diff --git a/example/client-cpp-example/src/CMakeLists.txt
b/example/client-cpp-example/src/CMakeLists.txt
index 1b902ceaa57..79d554037d3 100644
--- a/example/client-cpp-example/src/CMakeLists.txt
+++ b/example/client-cpp-example/src/CMakeLists.txt
@@ -39,13 +39,16 @@ LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/lib)
ADD_EXECUTABLE(SessionExample SessionExample.cpp)
ADD_EXECUTABLE(AlignedTimeseriesSessionExample
AlignedTimeseriesSessionExample.cpp)
ADD_EXECUTABLE(TableModelSessionExample TableModelSessionExample.cpp)
+ADD_EXECUTABLE(MultiSvrNodeClient MultiSvrNodeClient.cpp)
IF(MSVC)
TARGET_LINK_LIBRARIES(SessionExample iotdb_session
"${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib")
TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample iotdb_session
"${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib")
TARGET_LINK_LIBRARIES(TableModelSessionExample iotdb_session
"${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib")
+ TARGET_LINK_LIBRARIES(MultiSvrNodeClient iotdb_session
"${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib")
ELSE()
TARGET_LINK_LIBRARIES(SessionExample iotdb_session pthread)
TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample iotdb_session
pthread)
TARGET_LINK_LIBRARIES(TableModelSessionExample iotdb_session pthread)
-ENDIF()
+ TARGET_LINK_LIBRARIES(MultiSvrNodeClient iotdb_session pthread)
+ENDIF()
\ No newline at end of file
diff --git a/iotdb-client/client-cpp/src/example/MultiSvrNodeClient.cpp
b/example/client-cpp-example/src/MultiSvrNodeClient.cpp
similarity index 100%
rename from iotdb-client/client-cpp/src/example/MultiSvrNodeClient.cpp
rename to example/client-cpp-example/src/MultiSvrNodeClient.cpp
diff --git a/iotdb-client/client-cpp/src/main/NodesSupplier.cpp
b/iotdb-client/client-cpp/src/main/NodesSupplier.cpp
index e5de1d94ebd..2cec43c4448 100644
--- a/iotdb-client/client-cpp/src/main/NodesSupplier.cpp
+++ b/iotdb-client/client-cpp/src/main/NodesSupplier.cpp
@@ -122,7 +122,9 @@ boost::optional<TEndPoint>
NodesSupplier::getQueryEndPoint() {
NodesSupplier::~NodesSupplier() {
stopBackgroundRefresh();
- client_->close();
+ if (client_ != nullptr) {
+ client_->close();
+ }
}
void NodesSupplier::deduplicateEndpoints() {
diff --git a/iotdb-client/client-cpp/src/main/Session.cpp
b/iotdb-client/client-cpp/src/main/Session.cpp
index 6b5dd6ab5d7..8182a67cccb 100644
--- a/iotdb-client/client-cpp/src/main/Session.cpp
+++ b/iotdb-client/client-cpp/src/main/Session.cpp
@@ -791,9 +791,11 @@ void Session::initDefaultSessionConnection() {
connected = true;
break;
+ } catch (const IoTDBException& e) {
+ log_debug(e.what());
+ throw;
} catch (const std::exception& e) {
- std::cout << "Failed to connect to " << endpoint.ip << ":"
- << endpoint.port << " , error=" << e.what() << std::endl;
+ log_warn(e.what());
}
}
diff --git a/iotdb-client/client-cpp/src/main/SessionBuilder.h
b/iotdb-client/client-cpp/src/main/SessionBuilder.h
index 34f92dd22f6..d1b11035609 100644
--- a/iotdb-client/client-cpp/src/main/SessionBuilder.h
+++ b/iotdb-client/client-cpp/src/main/SessionBuilder.h
@@ -83,7 +83,7 @@ public:
sqlDialect = "tree";
Session* newSession = new Session(this);
newSession->open(false);
- return new Session(this);
+ return newSession;
}
};
diff --git a/iotdb-client/client-cpp/src/test/cpp/sessionIT.cpp
b/iotdb-client/client-cpp/src/test/cpp/sessionIT.cpp
index 3c0657b07ef..18ccb2a8393 100644
--- a/iotdb-client/client-cpp/src/test/cpp/sessionIT.cpp
+++ b/iotdb-client/client-cpp/src/test/cpp/sessionIT.cpp
@@ -63,6 +63,19 @@ TEST_CASE("Create timeseries success", "[createTimeseries]")
{
session->deleteTimeseries("root.test.d1.s1");
}
+TEST_CASE("Login Test - Authentication failed with error code 801",
"[Authentication]") {
+ CaseReporter cr("Login Test");
+
+ try {
+ Session session("127.0.0.1", 6667, "root", "wrong-password");
+ session.open(false);
+ FAIL("Expected authentication exception"); // Test fails if no
exception
+ } catch (const std::exception& e) {
+ // Verify exception contains error code 801
+ REQUIRE(std::string(e.what()).find("801") != std::string::npos);
+ }
+}
+
TEST_CASE("Test Session constructor with nodeUrls", "[SessionInitAndOperate]")
{
CaseReporter cr("SessionInitWithNodeUrls");