Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit b19d719

Browse files
committed
Delete project when it fails to start
This is usually because the project's Docker configuration is wrong. If we don't delete the container, it can be unclear to the user whether we're trying to create the container and it's failing or the container is just being started.
1 parent 06e9a16 commit b19d719

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

project.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"go.coder.com/sail/internal/dockutil"
67
"net"
78
"os"
89
"os/exec"
@@ -276,3 +277,10 @@ func (p *project) open() error {
276277
flog.Info("opening %v", u)
277278
return browserapp.Open(u)
278279
}
280+
281+
func (p *project) delete() error {
282+
cli := dockerClient()
283+
defer cli.Close()
284+
285+
return dockutil.StopRemove(context.Background(), cli, p.cntName())
286+
}

runcmd.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ func (c *runcmd) handle(gf globalFlags, fl *flag.FlagSet) {
6363

6464
err = proj.open()
6565
if err != nil {
66-
flog.Fatal("failed to open project: %v", err)
66+
flog.Error("failed to open project: %v", err)
67+
err = proj.delete()
68+
if err != nil {
69+
flog.Error("failed to delete project container: %v", err)
70+
}
71+
os.Exit(1)
6772
}
6873
return
6974
}

0 commit comments

Comments
 (0)