Properly report process exits

This commit is contained in:
Derek Parker 2015-06-21 13:08:14 -05:00
parent 687dc4172d
commit 48bb398c4b
4 changed files with 17 additions and 12 deletions

@ -85,7 +85,7 @@ type ProcessExitedError struct {
}
func (pe ProcessExitedError) Error() string {
return fmt.Sprintf("process %d has exited with status %d", pe.Pid, pe.Status)
return fmt.Sprintf("Process %d has exited with status %d", pe.Pid, pe.Status)
}
// Attach to an existing process with the given PID.

@ -181,10 +181,7 @@ func (d *Debugger) Command(command *api.DebuggerCommand) (*api.DebuggerState, er
err = d.process.RequestManualStop()
}
if err != nil {
// Only report the error if it's not a process exit.
if _, exited := err.(proc.ProcessExitedError); !exited {
return nil, err
}
return nil, err
}
return d.State()
}

@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
protest "github.com/derekparker/delve/proc/test"
@ -68,8 +69,15 @@ func TestClientServer_exit(t *testing.T) {
t.Fatalf("Expected exited %v, got %v", e, a)
}
state, err = c.Continue()
if err == nil {
t.Fatalf("Expected error after continue, got none")
}
if !strings.Contains(err.Error(), "exited") {
t.Fatal("Expected exit message")
}
state, err = c.GetState()
if err != nil {
t.Fatalf("Unexpected error: %v, state: %#v", err, state)
t.Fatal(err)
}
if state.CurrentThread == nil {
t.Fatalf("Expected CurrentThread")

@ -12,7 +12,6 @@ import (
"github.com/peterh/liner"
sys "golang.org/x/sys/unix"
"github.com/derekparker/delve/proc"
"github.com/derekparker/delve/service"
)
@ -91,11 +90,12 @@ func (t *Term) Run() (error, int) {
cmd := cmds.Find(cmdstr)
if err := cmd(t.client, args...); err != nil {
switch err.(type) {
case proc.ProcessExitedError:
pe := err.(proc.ProcessExitedError)
fmt.Fprintf(os.Stderr, "Process exited with status %d\n", pe.Status)
default:
// The type information gets lost in serialization / de-serialization,
// so we do a string compare on the error message to see if the process
// has exited, or if the command actually failed.
if strings.Contains(err.Error(), "exited") {
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Fprintf(os.Stderr, "Command failed: %s\n", err)
}
}