dap: pass exit code through exited event
Pass the exit code through the exited event back to the client and ensure that the printed text is printed completely. Previously, the exited event just had a big todo and the printer would sometimes fail to send messages to the connected client. This moves the printer wait to before the debug adapter is closed to ensure that all messages get sent through the connection to the editor. While there, I also plumbed in the exit code to exited. It's not necessarily the real exit code but it will produce a zero on build success and a non-zero code on build failure so that should be good enough. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
+22
-10
@@ -83,7 +83,7 @@ func (d *Adapter[C]) Start(conn Conn) (C, error) {
|
||||
return resp.Config, resp.Error
|
||||
}
|
||||
|
||||
func (d *Adapter[C]) Stop() error {
|
||||
func (d *Adapter[C]) Stop(retErr error) error {
|
||||
if d.eg == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -94,15 +94,27 @@ func (d *Adapter[C]) Stop() error {
|
||||
Event: "terminated",
|
||||
},
|
||||
}
|
||||
// TODO: detect exit code from threads
|
||||
// c.C() <- &dap.ExitedEvent{
|
||||
// Event: dap.Event{
|
||||
// Event: "exited",
|
||||
// },
|
||||
// Body: dap.ExitedEventBody{
|
||||
// ExitCode: exitCode,
|
||||
// },
|
||||
// }
|
||||
|
||||
// Send an exit code based on the returned error.
|
||||
// Any error results in sending an exit code of 1 while
|
||||
// no error sends zero for success.
|
||||
//
|
||||
// The exited event is sent after the terminated event.
|
||||
// See the specification overview diagram on the bottom of the page
|
||||
// for a detailed flowchart.
|
||||
// https://microsoft.github.io/debug-adapter-protocol/overview
|
||||
exitCode := 0
|
||||
if retErr != nil {
|
||||
exitCode = 1
|
||||
}
|
||||
c.C() <- &dap.ExitedEvent{
|
||||
Event: dap.Event{
|
||||
Event: "exited",
|
||||
},
|
||||
Body: dap.ExitedEventBody{
|
||||
ExitCode: exitCode,
|
||||
},
|
||||
}
|
||||
})
|
||||
d.srv.Stop()
|
||||
|
||||
|
||||
+1
-1
@@ -253,7 +253,7 @@ func NewTestAdapter[C LaunchConfig](t *testing.T) (*Adapter[C], Conn, *daptest.C
|
||||
client := daptest.NewClient(clientConn)
|
||||
t.Cleanup(func() { client.Close() })
|
||||
|
||||
t.Cleanup(func() { adapter.Stop() })
|
||||
t.Cleanup(func() { adapter.Stop(nil) })
|
||||
return adapter, srvConn, client
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user