Skip to content

Commit 21afc1f

Browse files
authored
Allow sqlcmd delete to succeed if container has already been deleted (#286)
1 parent d479b3d commit 21afc1f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

cmd/modern/root/uninstall.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (c *Uninstall) run() {
101101
output.Fatal("Operation cancelled.")
102102
}
103103
}
104-
if !c.force {
104+
if controller.ContainerExists(id) && !c.force {
105105
output.Infof("Verifying no user (non-system) database (.mdf) files")
106106
if !controller.ContainerRunning(id) {
107107
output.FatalfWithHintExamples([][]string{
@@ -112,16 +112,20 @@ func (c *Uninstall) run() {
112112
c.userDatabaseSafetyCheck(controller, id)
113113
}
114114

115-
output.Infof(
116-
"Stopping %s",
117-
endpoint.ContainerDetails.Image,
118-
)
119-
err := controller.ContainerStop(id)
120-
c.CheckErr(err)
121-
122115
output.Infof("Removing context %s", config.CurrentContextName())
123-
err = controller.ContainerRemove(id)
124-
c.CheckErr(err)
116+
117+
if controller.ContainerExists(id) {
118+
output.Infof(
119+
"Stopping %s",
120+
endpoint.ContainerDetails.Image,
121+
)
122+
err := controller.ContainerStop(id)
123+
c.CheckErr(err)
124+
err = controller.ContainerRemove(id)
125+
c.CheckErr(err)
126+
} else {
127+
output.Warnf("Container %q no longer exists, continuing to remove context...", id)
128+
}
125129
}
126130

127131
config.RemoveCurrentContext()

0 commit comments

Comments
 (0)