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: add project config validation when using args, fixes #5445 #5452

Merged
merged 7 commits into from Nov 21, 2023

Conversation

stasadev
Copy link
Member

The Issue

How This PR Solves The Issue

Runs validation check for every projects that you pass to any DDEV command that uses args, so fixes more than just ddev start.

Manual Testing Instructions

See the issue.

Automated Testing Overview

Related Issue Link(s)

Release/Deployment Notes

@stasadev stasadev requested a review from a team as a code owner October 24, 2023 12:09
@github-actions
Copy link

github-actions bot commented Oct 24, 2023

@rfay rfay marked this pull request as draft October 24, 2023 20:10
Copy link
Member

@rfay rfay left a comment

Choose a reason for hiding this comment

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

A little more work to do on tests, changed it back to draft.

@rfay rfay added this to the v1.22.5 milestone Oct 27, 2023
@stasadev stasadev force-pushed the 20231024_stasadev_validate_project_config branch 2 times, most recently from 9578fc0 to 58856b8 Compare November 16, 2023 22:02
@stasadev stasadev marked this pull request as ready for review November 17, 2023 10:51
@rfay rfay force-pushed the 20231024_stasadev_validate_project_config branch from 58856b8 to b496f7e Compare November 18, 2023 01:15
@rfay
Copy link
Member

rfay commented Nov 18, 2023

Rebased

Copy link
Member

@rfay rfay left a comment

Choose a reason for hiding this comment

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

I'm confused about returning nil on error there, but it does function correctly in manual testing.

The one important thing to do is to improve the message. Currently we see something like Failed to get project(s): unsupported PHP version: xx.1, DDEV only supports the following versions: [5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3] but we need to identify the project that failed, so `Failed to load project 'projectname': ...

@@ -462,6 +461,11 @@ func (app *DdevApp) ValidateConfig() error {
return err
}

// Stop here if no config found
if err := CheckForMissingProjectFiles(app); err != nil {
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we be returning the error here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added more comments on this check.

@stasadev stasadev force-pushed the 20231024_stasadev_validate_project_config branch from b496f7e to a25f6a0 Compare November 20, 2023 20:14
Copy link
Member Author

@stasadev stasadev left a comment

Choose a reason for hiding this comment

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

I added the project name to the error message for each validation check.

@@ -462,6 +461,11 @@ func (app *DdevApp) ValidateConfig() error {
return err
}

// Stop here if no config found
if err := CheckForMissingProjectFiles(app); err != nil {
return nil
Copy link
Member Author

Choose a reason for hiding this comment

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

Added more comments on this check.

@@ -46,7 +46,7 @@ func getRequestedProjects(names []string, all bool) ([]*ddevapp.DdevApp, error)
if requestedProjectsMap[name], exists = allProjectMap[name]; !exists {
p := globalconfig.GetProject(name)
if p != nil && p.AppRoot != "" {
requestedProjectsMap[name] = &ddevapp.DdevApp{Name: name}
requestedProjectsMap[name] = &ddevapp.DdevApp{Name: name, AppRoot: p.AppRoot}
Copy link
Member Author

Choose a reason for hiding this comment

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

When you run ddev start <project> for a project with missing files, the error does not include the path:

Failed to start test-project: ddev can no longer find your project files at . If you would like...

And now it does:

Failed to start test-project: ddev can no longer find your project files at /home/stas/code/ddev/test-project. If you would like...

@rfay rfay force-pushed the 20231024_stasadev_validate_project_config branch from 124c355 to a105ef9 Compare November 21, 2023 15:07
@rfay
Copy link
Member

rfay commented Nov 21, 2023

Rebased for first chance to use the new testing stuff. Reviewing.

Copy link
Member

@rfay rfay left a comment

Choose a reason for hiding this comment

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

This looks great to me. Lots of improvements to user communication. 💯

One weird thing I encountered was on ddev start -a with a broken config on one of the projects (ddev.com), t:ype: xxx. It happily tried to start ddev.com (and didn't report errors) even though the config was invalid. I imagine that ddev start -a doesn't validate config. We don't have to fix that here.

@stasadev
Copy link
Member Author

stasadev commented Nov 21, 2023

I imagine that ddev start -a doesn't validate config. We don't have to fix that here.

Yes, there seems to be no check with the --all flag.

This should be easy to fix with:

--- a/cmd/ddev/cmd/utils.go
+++ b/cmd/ddev/cmd/utils.go
@@ -27,6 +27,13 @@ func getRequestedProjects(names []string, all bool) ([]*ddevapp.DdevApp, error) 
 
 	// If all projects are requested, return here
 	if all {
+		for _, project := range allProjects {
+			err = project.ValidateConfig()
+			if err != nil {
+				return nil, err
+			}
+		}
+
 		return allProjects, nil
 	}

I can add this fix in a new PR, or here.

@rfay
Copy link
Member

rfay commented Nov 21, 2023

Let's save it for a new PR, which can either go into this week's release or not, so we don't hold this one up.

You can pull this one when you want. The orbstack results will be interesting if you have time to wait for them, but I imagine we'll have things to learn anyway.

@rfay rfay merged commit 3d79c10 into ddev:master Nov 21, 2023
17 of 18 checks passed
@stasadev stasadev deleted the 20231024_stasadev_validate_project_config branch November 21, 2023 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants