Skip to content
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

fix: Windows specific path problem #1649

Closed
wants to merge 1 commit into from
Closed

Conversation

tippenein
Copy link
Collaborator

fixes #1634

I need to test this on a windows machine, but I believe if we normalize the windows format before getting the path we should be ok. Added some tests which may be useful..

@tippenein tippenein force-pushed the bmo/window-file-path branch from 6f2a1c7 to c6d0b7c Compare January 23, 2025 22:24
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

Attention: Patch coverage is 92.42424% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
components/clarinet-files/src/lib.rs 92.42% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@hugocaillard hugocaillard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may be able to avoid (as much as possible) to write specific code for the different platform (macos/linux/windows) – dealing with native/wasm is already being error prone.
Also, the original issue #1634 seems to highlight that it also break in a wasm context (otherwise, Clarinet would be fully broken on Windows).

I udpated the CI so that we run the SDK unit tests on all platforms (#1650) - still working on that.

It should allow use to see the error in #1634 (or we should add a test that triggers it).

And we should print the actual error here and there to get a better understanding of what's happening.

Still, I think this PR is heading in the right direction, FileLocation needs some improvements to be more robust and less error prone

Comment on lines +104 to +110
// Handle Windows-style paths specially
if url_string.contains('\\') || url_string.contains(':') {
let path = PathBuf::from(url_string);
if path.exists() {
return Ok(FileLocation::FileSystem { path });
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an issue with this code.
from_url_string kind of assume that we are passing a valid url and that we should return a FileLocation:Url.
If not, from_path_string is called.
And Url should never be "windows style"

Is there an issue in how we handle it here?

One other approach could be to have a generic From<String> that just sort of handle it.

impl From<String> for FileLocation {
    fn from(location_string: String) -> Self {
        if let Ok(location) = FileLocation::from_url_string(&location_string) {
            return location;
        }
        if let Ok(location) = FileLocation::from_path_string(&location_string) {
            return location;
        }
        panic!("Invalid location string: {}", location_string);
    }
}

Could be a good opportunity to implement From<PathBuf> and From<Url> and get a bit more idomatic (instead of the custom functions that we have now)

The point is that Path adn PathBuf should be platform agnostic and we shouldn't have to deal with it, looks like it will get even more error prone.

@tippenein tippenein closed this Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Absolute manifest path cannot be used to initialize a simnet session on Windows
2 participants