-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Use non-throwing std::filesystem functions in the type registry #1472
Conversation
@@ -77,18 +77,23 @@ caf::error type_registry_state::save_to_disk() const { | |||
|
|||
caf::error type_registry_state::load_from_disk() { | |||
// Nothing to load is not an error. | |||
if (!exists(dir)) { | |||
std::error_code err{}; |
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.
Was this picked up via ADL? My goodness.
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.
dir
is of type std::filesystem::path
, so what else would you expect?
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.
No surprise we didn't catch this one during review.
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.
Gotta love ADL. 😒
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.
Ouch. Sorry I missed this when I introduced this change 😞
Thanks for the fix.
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.
No worries, these things happen.
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 is one of those things that are only obvious in hindsight. We probably would have run into the exact same issue.
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.
Pedantically, can you help me understand why exists
unqualified would pick up std::filesystem::exists
? I don't see us do a using namespace std;
or anything like that. Who's bringing it into scope?
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.
See this recent article on (among other things) ADL: https://preshing.com/20210315/how-cpp-resolves-a-function-call/
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.
I did not test locally. This should be covered by CI. Did you verify that this fixes the issue with the systemd setup?
Not yet, I wanted to use the CI artifact for that. |
Consider it approved if the issue is fixed ;) |
c5f3dbc
to
0b2da3b
Compare
It is indeed fixed. |
auto dirs = get_schema_dirs(self->system().config()); | ||
concepts_map concepts; | ||
models_map models; | ||
for (const auto& dir : dirs) { | ||
if (!exists(dir)) | ||
auto dir_exists = std::filesystem::exists(dir, err); | ||
if (err) |
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.
I think we should do err.clear()
. In the case where more than one directory doesn't exist (and since we continue in the loop), I think we want to warn on just the ones that don't exist rather than erroneously warn on all of the dirs remaining after the first one fails (and thus err
is set). Does that make sense? 🤔
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.
exists()
calls err.clear()
itself if it didn't fail. See https://en.cppreference.com/w/cpp/filesystem/exists.
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.
Ah, perfect then. 👍
... in the type registry.
0b2da3b
to
0836774
Compare
📔 Description
Change 2 use sites of
exists()
.📝 Checklist