Skip to content

Commit

Permalink
ENH: Enhance error messages from ValidateDirectoryWritePermission()
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Apr 12, 2024
1 parent a57df57 commit 48a314c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/simplnx/Utilities/FileUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
}
}

Expand All @@ -207,19 +209,20 @@ 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.
if(HasWriteAccess(checkedPath.string()))
{
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

0 comments on commit 48a314c

Please sign in to comment.