diff --git a/CMakeLists.txt b/CMakeLists.txt index 17881be..3c52ee8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,19 +91,23 @@ list(APPEND mdio_TEST_COPTS "-Wno-unknown-warning-option") # Define the internal dependencies that should be linked -set(mdio_INTERNAL_DEPS - tensorstore::driver_array - tensorstore::driver_zarr - tensorstore::driver_json - tensorstore::kvstore_file - tensorstore::kvstore_memory - tensorstore::tensorstore - tensorstore::index_space_dim_expression - tensorstore::index_space_index_transform - tensorstore::util_status_testutil - tensorstore::driver_array - PARENT_SCOPE -) +if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + # This is not the top-level project + set(mdio_INTERNAL_DEPS + tensorstore::driver_array + tensorstore::driver_zarr + tensorstore::driver_json + tensorstore::kvstore_file + tensorstore::kvstore_memory + tensorstore::tensorstore + tensorstore::index_space_dim_expression + tensorstore::index_space_index_transform + tensorstore::util_status_testutil + tensorstore::kvstore_gcs + tensorstore::driver_array + PARENT_SCOPE + ) +endif() # Define internal deps for cloud specific drivers set(mdio_INTERNAL_GCS_DRIVER_DEPS diff --git a/mdio/dataset.h b/mdio/dataset.h index 394e0c1..b5154f7 100644 --- a/mdio/dataset.h +++ b/mdio/dataset.h @@ -293,8 +293,14 @@ from_zmetadata(const std::string& dataset_path) { // FIXME - enable async auto kvs_future = mdio::internal::dataset_kvs_store(dataset_path).result(); + if (!kvs_future.ok()) { + return internal::CheckMissingDriverStatus(kvs_future.status()); + } auto kvs_read_result = tensorstore::kvstore::Read(kvs_future.value(), ".zmetadata").result(); + if (!kvs_read_result.ok()) { + return internal::CheckMissingDriverStatus(kvs_read_result.status()); + } ::nlohmann::json zmetadata; try { diff --git a/mdio/variable.h b/mdio/variable.h index 364bb19..9b8aca8 100644 --- a/mdio/variable.h +++ b/mdio/variable.h @@ -80,6 +80,41 @@ struct SliceDescriptor { }; namespace internal { + +/** + * @brief Checks a status for a missing driver message and returns an MDIO + * specific error message. + * @param status The status to check + * @return A driver specific message if the status is a missing driver message, + * otherwise the original status. + */ +absl::Status CheckMissingDriverStatus(const absl::Status& status) { + std::string error(status.message()); + if (error.find("Error parsing object member \"driver\"") != + std::string::npos) { + if (error.find("is not registered") != std::string::npos) { + if (error.find("gcs") != std::string::npos) { + return absl::InvalidArgumentError( + "A GCS path was detected but the GCS driver was not " + "registered.\nPlease ensure that your CMake includes the " + "mdio_INTERNAL_GCS_DRIVER_DEPS variable."); + } else if (error.find("s3") != std::string::npos) { + return absl::InvalidArgumentError( + "An S3 path was detected but the S3 driver was not " + "registered.\nPlease ensure that your CMake includes the " + "mdio_INTERNAL_S3_DRIVER_DEPS variable."); + } else { + return absl::InvalidArgumentError( + "An unexpected driver registration error has occured. Please file " + "a bug report with the error message to " + "https://github.com/TGSAI/mdio-cpp/issues\n" + + error); + } + } + } + return status; +} + /** * @brief Validates and processes a JSON specification for a tensorstore * variable. @@ -358,7 +393,7 @@ Future> CreateVariable(const nlohmann::json& json_spec, tensorstore::ReadyFuture readyFut) { auto ready_result = readyFut.result(); if (!ready_result.ok()) { - promise.SetResult(ready_result.status()); + promise.SetResult(CheckMissingDriverStatus(ready_result.status())); } else { promise.SetResult(variable_future.result()); }