From 48a314c3476582f1c0568e6e6d6102c0cea3164b Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Fri, 12 Apr 2024 11:59:29 -0400 Subject: [PATCH] ENH: Enhance error messages from ValidateDirectoryWritePermission() Signed-off-by: Michael Jackson --- src/simplnx/Utilities/FileUtilities.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/simplnx/Utilities/FileUtilities.cpp b/src/simplnx/Utilities/FileUtilities.cpp index 988df77167..b361455b6b 100644 --- a/src/simplnx/Utilities/FileUtilities.cpp +++ b/src/simplnx/Utilities/FileUtilities.cpp @@ -168,7 +168,7 @@ Result<> ValidateDirectoryWritePermission(const fs::path& path, bool isFile) { if(path.empty()) { - return MakeErrorResult(-16, "ValidateDirectoryWritePermission() error: given path was empty."); + return MakeErrorResult(-16, "ValidateDirectoryWritePermission() Error: Input path empty."); } auto checkedPath = path; @@ -186,7 +186,9 @@ Result<> ValidateDirectoryWritePermission(const fs::path& path, bool isFile) checkedPath = fs::absolute(checkedPath); } catch(const std::filesystem::filesystem_error& error) { - return MakeErrorResult(-15, fmt::format("ValidateDirectoryWritePermission() threw an error: '{}'", error.what())); + return MakeErrorResult(-15, fmt::format("ValidateDirectoryWritePermission() Error: Input Path '{}' was relative and trying to create an absolute path threw an exception with message '{}'. " + "Further error code and message from the file system was: Code={} Message={}", + path.string(), error.what(), error.code().value(), error.code().message())); } } @@ -207,12 +209,13 @@ Result<> ValidateDirectoryWritePermission(const fs::path& path, bool isFile) if(checkedPath.empty()) { - return MakeErrorResult(-19, "ValidateDirectoryWritePermission() resolved path was empty"); + return MakeErrorResult(-19, fmt::format("ValidateDirectoryWritePermission() Error: Input path '{}' resolved to an empty path", path.string())); } if(!fs::exists(checkedPath)) { - return MakeErrorResult(-11, fmt::format("ValidateDirectoryWritePermission() error: The drive does not exist on this system: '{}'", checkedPath.string())); + return MakeErrorResult(-11, + fmt::format("ValidateDirectoryWritePermission() Error: Input Path '{}' resolved to '{}'. The drive does not exist on this system.", path.string(), checkedPath.string())); } // We should be at the top of the tree with an existing directory. @@ -220,6 +223,6 @@ Result<> ValidateDirectoryWritePermission(const fs::path& path, bool isFile) { return {}; } - return MakeErrorResult(-8, fmt::format("User does not have write permissions to path '{}'", path.string())); + return MakeErrorResult(-8, fmt::format("ValidateDirectoryWritePermission() Error: User does not have write permissions to path '{}'", path.string())); } } // namespace nx::core::FileUtilities