-
Notifications
You must be signed in to change notification settings - Fork 13.9k
ggml: use 'exists( const std::filesystem::path&, std::error_code&)' instead of 'exists( const std::filesystem::path&)' to enhance robustness #17653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Refactor existence checks for search paths using std::error_code to handle potential errors.
Update fs::exists to use std::error_code for error handling.
ggml/src/ggml-backend-reg.cpp
Outdated
| if (!fs::exists(search_path)) { | ||
| GGML_LOG_DEBUG("%s: search path %s does not exist\n", __func__, path_str(search_path).c_str()); | ||
| std::error_code ec; | ||
| bool is_exist = fs::exists(search_path, ec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this could be written as:
std::error_code ec;
if (!fs::exists(search_path, ec)) {
if (ec){
GGML_LOG_DEBUG("%s: posix_stat(%s) failure, error-message: %s\n", __func__, path_str(search_path).c_str(), ec.message().c_str());
} else{
GGML_LOG_DEBUG("%s: search path %s does not exist\n", __func__, path_str(search_path).c_str());
}
continue;
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, Simplify it now.
| fs::path path = search_path / filename; | ||
| if (fs::exists(path)) { | ||
| std::error_code ec; | ||
| if (fs::exists(path, ec)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably log the exception if it happens so that it does not just silently fail now.
Alternatively we could create a list of valid paths that we get from the previous iteration where they are already checked and then just use the exists function that throws an exception here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve-log is effective and simple, now, it's ready.
Simplify existence check for search paths
| std::error_code ec; | ||
| if (!fs::exists(search_path, ec)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be further simplified using if-init
| std::error_code ec; | |
| if (!fs::exists(search_path, ec)) { | |
| if (std::error_code ec; !fs::exists(search_path, ec)) { |
rgerganov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RPC changes are fine
When use
exists( const std::filesystem::path& p), ifpcan't access(like: Permission denied), it will throwstd::filesystem::filesystem_errorto break the execution flow.