Use safeClose instead of Close

This commit is contained in:
JP Ungaretti 2022-04-28 18:38:46 +00:00 committed by GitHub
parent 6ddd3360d8
commit ceba2c896b
4 changed files with 7 additions and 8 deletions

View file

@ -27,7 +27,7 @@ func newJupyterCmd(app *App) *cobra.Command {
return jupyterCmd
}
func (a *App) Jupyter(ctx context.Context, codespaceName string) error {
func (a *App) Jupyter(ctx context.Context, codespaceName string) (err error) {
// Ensure all child tasks (e.g. port forwarding) terminate before return.
ctx, cancel := context.WithCancel(ctx)
defer cancel()
@ -41,7 +41,7 @@ func (a *App) Jupyter(ctx context.Context, codespaceName string) error {
if err != nil {
return err
}
defer session.Close()
defer safeClose(session, &err)
a.StartProgressIndicatorWithLabel("Starting JupyterLab on codespace")
serverPort, serverUrl, err := session.StartJupyterServer(ctx)

View file

@ -45,7 +45,7 @@ func (a *App) Logs(ctx context.Context, codespaceName string, follow bool) (err
if err != nil {
return err
}
defer session.Close()
defer safeClose(session, &err)
// Ensure local port is listening before client (getPostCreateOutput) connects.
listen, err := net.Listen("tcp", "127.0.0.1:0") // arbitrary port

View file

@ -59,7 +59,7 @@ func (a *App) ListPorts(ctx context.Context, codespaceName string, exporter cmdu
if err != nil {
return err
}
defer session.Close()
defer safeClose(session, &err)
a.StartProgressIndicatorWithLabel("Fetching ports")
ports, err := session.GetSharedServers(ctx)

View file

@ -125,7 +125,7 @@ func (a *App) SSH(ctx context.Context, sshArgs []string, opts sshOptions) (err e
if err != nil {
return err
}
defer session.Close()
defer safeClose(session, &err)
a.StartProgressIndicatorWithLabel("Fetching SSH Details")
remoteSSHServerPort, sshUser, err := session.StartSSHServer(ctx)
@ -187,11 +187,10 @@ func (a *App) SSH(ctx context.Context, sshArgs []string, opts sshOptions) (err e
}
}
func (a *App) printOpenSSHConfig(ctx context.Context, opts sshOptions) error {
func (a *App) printOpenSSHConfig(ctx context.Context, opts sshOptions) (err error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
var err error
var csList []*api.Codespace
if opts.codespace == "" {
a.StartProgressIndicatorWithLabel("Fetching codespaces")
@ -232,7 +231,7 @@ func (a *App) printOpenSSHConfig(ctx context.Context, opts sshOptions) error {
if err != nil {
result.err = fmt.Errorf("error connecting to codespace: %w", err)
} else {
defer session.Close()
defer safeClose(session, &err)
_, result.user, err = session.StartSSHServer(ctx)
if err != nil {