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: world cardinal dev not exit on compilation error #63

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmd/world/cardinal/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ var devCmd = &cobra.Command{
return err
}

// Start a goroutine to check cmd is stopped
go func() {
err := execCmd.Wait()
if err != nil {
logger.Error(eris.Wrap(err, "Cardinal process stopped"))
}

// if process exited, send signal to StopChan
signalCh <- syscall.SIGTERM
}()

// Start a goroutine to listen for signals
go func() {
<-signalCh
Expand Down Expand Up @@ -255,6 +266,10 @@ func stopCardinal(cmd *exec.Cmd, watch bool) error {
return nil
}

if cmd.ProcessState == nil || cmd.ProcessState.Exited() {
return nil
}

// stop the cardinal process
if runtime.GOOS == "windows" {
err := cmd.Process.Kill()
Expand Down
4 changes: 2 additions & 2 deletions cmd/world/root/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestDev(t *testing.T) {
assert.NilError(t, err)

// Start cardinal dev
rootCmd.SetArgs([]string{"cardinal", "dev", "--watch"})
rootCmd.SetArgs([]string{"cardinal", "dev"})
go func() {
err := rootCmd.Execute()
assert.NilError(t, err)
Expand All @@ -238,7 +238,7 @@ func TestDev(t *testing.T) {
assert.Assert(t, isGameLoopRunning)

// Shutdown the program
close(cardinal.StopChan)
cardinal.StopChan <- struct{}{}

// Check cardinal health (expected error), trying for 10 times
count := 0
Expand Down