Repository navigation
Add path.exists function - #7556
laurmaedje wants to merge 1 commit into
Conversation
6f312bd to
a2aa127
Compare
c86fca2 to
18f366f
Compare
a2aa127 to
9d2f0d9
Compare
18f366f to
125fca8
Compare
|
Regardless of impl concerns: Is there really a use case, where separating path construction and validation makes sense? My imagination falls short, atm. I can imagine, however, that cost of exposing this api might outweigh the benefit. |
Could you elaborate? The idea is to check something "does this image exist" before calling the |
|
Got ya. What would this placeholder be useful for? - I have little depth of context / authority to hold a strong opinion. Without that context, I could believe that it would be beneficial to fail on construction if the path does not exists. - as an implementation of a "fail early and hard" principle. Since paths can't break out the project root, I reason that users of If they do, we can assume it's a genuine mistake (e.g. typing error), hence omitting to fail upon construction delays the user facing error / fix. In a scenario where paths could indeed break out the project root scope (which they can't), I could imagine a case where a user would want to construct and inventorize on purpose a path that does not (yet - in the context of construction) exist. To a certain extend and in this line of thinking, it feels like this feature "contradicts" the enforcement repository scope. |
|
IMO, if we were to use the design that To avoid double-checking, we may need something like |
I find this an interesting proposal, indeed. This would have good use cases at the boundary between old string paths and new paths and could be a valuable tool for library (package) authors. E.g. |
|
Considering that #2025 has thirty upvotes and many use cases, people seem to have lots of use cases for checking if a path exists. Personally, I don't really see the point in failing on path construction. It complicates the API design for existence checks (e.g. To me, the path is just a description of something that might be in the file system and the load operation is what fails when the file does not exist. |
Just to quickly counter the impression it might give: that's technically unrelated to the proposal, to fail on construction.
Besides the principled concern "fail fast and hard", I explained, there's also an error context coming to my mind. If the path fails later, it is harder to trace where the path had been construed, and to ease this, some additional position context would have to be passed into the path type. And knowing quickly what went wrong where with proper error context is not something of 0 value in a typo scenario, for example.
In VSCode, when I click here, I'm directly led to the correct code line where the wrong path had been added.
I can't give a proper opinion, but if this is the tradeoff and preferences, then I indeed have nothing useful to add.
Indeed. Overall, I think I made my point well enough for your appreciation 😄 - Thanks for this little back & forth. I'll not push the proposal further. |
125fca8 to
f439c9a
Compare
f439c9a to
df7c696
Compare
|
One small suggestion (for a future PR if any). If this gets added (hopefully), it would be beneficial to extend the JSON dependencies format with a list of files whose existence was checked. For example, a document #let cases = if path("cases.json").exists() {
json("cases.json")
} else {
("case1", "case2")
}Then
This would make it possible for a build system to decide that a document needs to be recompiled when a file |
|
I like the recent movement on this topic. Any clues on the decision, yet? |
|
I'm pretty busy right now, but this is still on my radar. |
|
The PR here is too hacky. This will need proper |

This PR adds support for a
path.existsfunction that checks whether a file or directory exists at a path. It depends on #7555.The implementation right now uses the existing
Worldinfrastructure. It tries to load the path, and matches on the result to make a decision. In particular, it depends on World implementors correctly returningFileError::IsDirectoryfor directories.I am not 100% decided whether we should keep it this way or whether we should extend the
Worldinterface to make this more explicit (maybe with a default impl mirroring what I've done here), also allowing it to be more efficient. We should also consider how theWorldinterface needs to be adapted to support directory walking. Maybe there is some overlap.The function also still needs some more documentation.
This closes #2025.