ソースを参照

fix(storage): tighten error codes and update() return contract

- update() plain success returns -1 (version unknown), not 0, so callers
  cannot confuse it with version 0 or accidentally bypass optimistic locking
  by feeding it back as expected_version.
- createCollection/remove failures now map to ErrorCode::DatabaseError instead
  of CollectionNotFound/DocumentNotFound; the upstream client returns false
  for any failure, not specifically "not found".
- cmake: move find_package(smartbotic-db-client) after find_package(PkgConfig)
  so the upstream Config can transitively use PkgConfig if needed.
fszontagh 2 ヶ月 前
コミット
381f1ec2fe

+ 3 - 3
cmake/FindPackages.cmake

@@ -1,10 +1,10 @@
 # Find system packages
 
-# Upstream smartbotic-database client library — provides target smartbotic::db-client
-find_package(smartbotic-db-client CONFIG REQUIRED)
-
 # Required packages
 find_package(PkgConfig REQUIRED)
+
+# Upstream smartbotic-database client library — provides target smartbotic::db-client
+find_package(smartbotic-db-client CONFIG REQUIRED)
 find_package(Threads REQUIRED)
 find_package(OpenSSL REQUIRED)
 find_package(CURL REQUIRED)

+ 5 - 3
lib/storage/storage_client.cpp

@@ -113,7 +113,9 @@ Result<int64_t> StorageClient::update(const std::string& collection,
     }
     bool ok = impl_->client_->update(collection, id, data);
     if (!ok) return Error(ErrorCode::DatabaseError, "Update failed: " + collection + "/" + id);
-    return 0;
+    // Upstream plain update() returns bool only; the new version is not exposed.
+    // Use -1 to signal "version unknown" so callers cannot mistake it for version 0.
+    return -1;
 }
 
 Result<void> StorageClient::remove(const std::string& collection,
@@ -121,7 +123,7 @@ Result<void> StorageClient::remove(const std::string& collection,
                                    int64_t expected_version) {
     (void)expected_version;  // upstream remove() is unconditional in 1.7.x
     bool ok = impl_->client_->remove(collection, id);
-    if (!ok) return Error(ErrorCode::DocumentNotFound, "Remove failed: " + collection + "/" + id);
+    if (!ok) return Error(ErrorCode::DatabaseError, "Remove failed: " + collection + "/" + id);
     return {};
 }
 
@@ -176,7 +178,7 @@ Result<void> StorageClient::createCollection(const std::string& name,
         /*encrypted=*/false,
         maxVersions,
         /*vectorDimension=*/0);
-    if (!ok) return Error(ErrorCode::CollectionNotFound, "createCollection failed: " + name);
+    if (!ok) return Error(ErrorCode::DatabaseError, "createCollection failed: " + name);
     return {};
 }
 

+ 5 - 0
lib/storage/storage_client.hpp

@@ -75,6 +75,11 @@ public:
                                        const std::string& id = "",
                                        int64_t ttl_ms = 0);
 
+    // Returns: the new version on optimistic-lock success (expected_version+1),
+    //          the new version on partial/patch success,
+    //          -1 when the update succeeded but the new version is unknown
+    //              (plain update path; upstream client doesn't expose it),
+    //          or an Error on failure.
     common::Result<int64_t> update(const std::string& collection,
                                    const std::string& id,
                                    const nlohmann::json& data,