-
Notifications
You must be signed in to change notification settings - Fork 182
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
Correct issue with default.project.json files with no name being named default
after change
#917
Correct issue with default.project.json files with no name being named default
after change
#917
Conversation
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 optional name handling should probably be consolidated into the project module. Having optional name logic done in two different places is harder to follow and gives too much room for mistakes, and I don't see any benefits in doing so.
I transferred the following block into a function in the project module (which is then called in Project::load_from_slice
and Project::load_exact
[maybe we should remove one of these too? I'm not sure why we need both]), and also moved the associated error variants into ProjectError
:
Lines 121 to 147 in 3d4e387
if root_project.name.is_none() { | |
if let Some(file_name) = project_path.file_name().and_then(|s| s.to_str()) { | |
if file_name == "default.project.json" { | |
let folder_name = project_path | |
.parent() | |
.and_then(Path::file_name) | |
.and_then(|s| s.to_str()); | |
if let Some(folder_name) = folder_name { | |
root_project.name = Some(folder_name.to_string()); | |
} else { | |
return Err(ServeSessionError::FolderNameInvalid { | |
path: project_path.to_path_buf(), | |
}); | |
} | |
} else if let Some(trimmed) = file_name.strip_suffix(".project.json") { | |
root_project.name = Some(trimmed.to_string()); | |
} else { | |
return Err(ServeSessionError::ProjectNameInvalid { | |
path: project_path.to_path_buf(), | |
}); | |
} | |
} else { | |
return Err(ServeSessionError::ProjectNameInvalid { | |
path: project_path.to_path_buf(), | |
}); | |
} | |
} |
So there is a problem with the above approach: sync rules mean that project files won't necessarily have |
I went through and redid the name resolution and it's now generalized. As long as we use the right methods on In the process, I did modify project loading to always use a Vfs, which impacts the fmt-project subcommand. Nothing invasive though. |
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.
Looking good, just a couple comments:
...I 100% brainfarted and added |
In #917, we accidentally changed ServeSession::new's project loading logic so that it always returns `ServeSession::ProjectNotFound` if the load fails for any reason. This PR fixes this so that it returns the right error when there is an error loading the project, and moves the `NoProjectFound` error to `project::Error`, since I think it makes more sense there.
Closes #916.
Turns out we had a test that should've caught this, it's just that nobody caught it when this feature was implemented. We'll likely want to backport this into the 7.4.x branch as well.
Let me know if you have a better way to calculate project names in the middleware, I'm not in love with the way it's implemented here.