Skip to content

Conversation

@flyinskyin2013
Copy link
Contributor

When use exists( const std::filesystem::path& p), if p can't access(like: Permission denied), it will throw std::filesystem::filesystem_error to break the execution flow.

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.
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);
Copy link
Member

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;
        }

Copy link
Contributor Author

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)) {
Copy link
Member

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.

Copy link
Contributor Author

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.

@github-actions github-actions bot added the ggml changes relating to the ggml tensor library for machine learning label Dec 1, 2025
Comment on lines +537 to +538
std::error_code ec;
if (!fs::exists(search_path, ec)) {
Copy link
Collaborator

@am17an am17an Dec 2, 2025

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

Suggested change
std::error_code ec;
if (!fs::exists(search_path, ec)) {
if (std::error_code ec; !fs::exists(search_path, ec)) {

Copy link
Collaborator

@rgerganov rgerganov left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants