From a3262cceeed0235b95f375f6abbaf3b0e3acbaff Mon Sep 17 00:00:00 2001 From: alesapin Date: Tue, 21 Jul 2020 14:21:13 +0300 Subject: [PATCH] Better exception during directories creation --- src/Access/DiskAccessStorage.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Access/DiskAccessStorage.cpp b/src/Access/DiskAccessStorage.cpp index 8b249813f7c..25740f012ac 100644 --- a/src/Access/DiskAccessStorage.cpp +++ b/src/Access/DiskAccessStorage.cpp @@ -329,9 +329,11 @@ void DiskAccessStorage::initialize(const String & directory_path_, Notifications throw Exception("Storage " + getStorageName() + " already initialized with another directory", ErrorCodes::LOGICAL_ERROR); } - std::filesystem::create_directories(canonical_directory_path); - if (!std::filesystem::exists(canonical_directory_path) || !std::filesystem::is_directory(canonical_directory_path)) - throw Exception("Couldn't create directory " + canonical_directory_path.string(), ErrorCodes::DIRECTORY_DOESNT_EXIST); + std::error_code create_dir_error_code; + std::filesystem::create_directories(canonical_directory_path, create_dir_error_code); + + if (!std::filesystem::exists(canonical_directory_path) || !std::filesystem::is_directory(canonical_directory_path) || create_dir_error_code) + throw Exception("Couldn't create directory " + canonical_directory_path.string() + " reason: '" + create_dir_error_code.message() + "'", ErrorCodes::DIRECTORY_DOESNT_EXIST); directory_path = canonical_directory_path; initialized = true;