Skip to content

Commit

Permalink
Do not try to start project for a snapshot, fixes #1129 (#1146)
Browse files Browse the repository at this point in the history
* Do not try to start project for a snapshot, fixes #1129

* Improve formatting and content of error messages for rm and snapshot

* Making important functions depend on literal error messages is fragile
  • Loading branch information
rfay committed Oct 2, 2018
1 parent 19063c0 commit 9cda214
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/ddev/cmd/remove.go
Expand Up @@ -58,7 +58,7 @@ To snapshot the database on remove, use "ddev remove --snapshot"; A snapshot is
// We do the snapshot if either --snapshot or --remove-data UNLESS omit-snapshot is set
doSnapshot := ((createSnapshot || removeData) && !omitSnapshot)
if err := app.Down(removeData, doSnapshot); err != nil {
util.Failed("Failed to remove ddev project %s: %v", app.GetName(), err)
util.Failed("Failed to remove project %s: \n%v", app.GetName(), err)
}

util.Success("Project %s has been removed.", app.GetName())
Expand Down
9 changes: 3 additions & 6 deletions pkg/ddevapp/ddevapp.go
Expand Up @@ -125,7 +125,7 @@ func (app *DdevApp) Init(basePath string) error {
return fmt.Errorf("a project (web container) in %s state already exists for %s that was created at %s", web.State, app.Name, containerApproot)
}
return nil
} else if strings.Contains(err.Error(), "could not find containers") {
} else if strings.Contains(err.Error(), "unable to find any running or stopped containers") {
// Init() is just putting together the DdevApp struct, the containers do
// not have to exist (app doesn't have to have been started, so the fact
// we didn't find any is not an error.
Expand Down Expand Up @@ -857,10 +857,7 @@ func (app *DdevApp) SnapshotDatabase(snapshotName string) (string, error) {
}

if app.SiteStatus() != SiteRunning {
err = app.Start()
if err != nil {
return snapshotName, fmt.Errorf("Failed to start project %s to snapshot database: %v", app.Name, err)
}
return "", fmt.Errorf("unable to snapshot database, \nyour project %v is not running. \nPlease start the project if you want to snapshot it. \nIf removing, you can remove without a snapshot using \n'ddev remove --remove-data --omit-snapshot', \nwhich will destroy your database", app.Name)
}

util.Warning("Creating database snapshot %s", snapshotName)
Expand Down Expand Up @@ -924,7 +921,7 @@ func (app *DdevApp) Down(removeData bool, createSnapshot bool) error {
// Remove all the containers and volumes for app.
err = Cleanup(app)
if err != nil {
return fmt.Errorf("failed to remove ddev project %s: %v", app.GetName(), err)
return err
}

// Remove data/database/hostname if we need to.
Expand Down
2 changes: 1 addition & 1 deletion pkg/dockerutil/dockerutils.go
Expand Up @@ -112,7 +112,7 @@ func FindContainersByLabels(labels map[string]string) ([]docker.APIContainers, e
// If we couldn't find a match return a list with a single (empty) element alongside the error.
if len(containerMatches) < 1 {
containerMatches = []docker.APIContainers{{}}
returnError = fmt.Errorf("could not find containers which matched search criteria: %+v", labels)
returnError = fmt.Errorf("unable to find any running or stopped containers")
}

return containerMatches, returnError
Expand Down

0 comments on commit 9cda214

Please sign in to comment.