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

Correct issue with default.project.json files with no name being named default after change #917

Merged
merged 12 commits into from
Jul 15, 2024

Conversation

Dekkonot
Copy link
Member

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.

@Dekkonot Dekkonot added the skip changelog PRs that may skip the changelog enforcement check label May 15, 2024
@Dekkonot Dekkonot requested a review from kennethloeffler May 15, 2024 16:59
Copy link
Member

@kennethloeffler kennethloeffler 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 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:

rojo/src/serve_session.rs

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(),
});
}
}

src/snapshot_middleware/project.rs Outdated Show resolved Hide resolved
@kennethloeffler
Copy link
Member

kennethloeffler commented May 20, 2024

So there is a problem with the above approach: sync rules mean that project files won't necessarily have .project.json as a suffix, meaning that such files must contain a name field, otherwise the project will fail to load with ProjectNameInvalid. I think we should still allow a missing name field in this case (it should also have a test!). I'd still like the optional name logic to be defined in one place, so maybe we should give the project load functions a name parameter to fall back to in case we can't strip the .project.json suffix?

@Dekkonot Dekkonot requested a review from kennethloeffler May 28, 2024 18:20
@Dekkonot
Copy link
Member Author

I went through and redid the name resolution and it's now generalized. As long as we use the right methods on Project, it'll always work the same now.

In the process, I did modify project loading to always use a Vfs, which impacts the fmt-project subcommand. Nothing invasive though.

Copy link
Member

@kennethloeffler kennethloeffler left a 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:

src/snapshot_middleware/mod.rs Outdated Show resolved Hide resolved
src/project.rs Outdated Show resolved Hide resolved
@Dekkonot
Copy link
Member Author

...I 100% brainfarted and added middleware to that last commit message even though it is not related to the middleware. Don't worry about it.

@Dekkonot Dekkonot merged commit 3ca975d into rojo-rbx:master Jul 15, 2024
6 checks passed
@Dekkonot Dekkonot deleted the woe-project-name-be-upon-you branch July 15, 2024 16:28
Dekkonot added a commit to Dekkonot/rojo that referenced this pull request Jul 22, 2024
Dekkonot added a commit that referenced this pull request Jul 22, 2024
kennethloeffler added a commit that referenced this pull request Nov 8, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip changelog PRs that may skip the changelog enforcement check
Projects
None yet
2 participants