Fix for nil logger on non-debugging scenarios

This commit is contained in:
Jose Garcia 2021-10-13 14:15:26 -04:00
parent a033b85fa2
commit d6b5157eff
2 changed files with 7 additions and 7 deletions

View file

@ -62,17 +62,21 @@ func (a *App) SSH(ctx context.Context, sshArgs []string, opts sshOptions) (err e
return fmt.Errorf("get or choose codespace: %w", err)
}
var debugLogger *fileLogger
var liveshareLogger *log.Logger
if opts.debug {
debugLogger, err = newFileLogger(opts.debugFile)
debugLogger, err := newFileLogger(opts.debugFile)
if err != nil {
return fmt.Errorf("error creating debug logger: %w", err)
}
defer safeClose(debugLogger, &err)
liveshareLogger = debugLogger.Logger
a.logger.Println("Debug file located at: " + debugLogger.Name())
} else {
liveshareLogger = noopLogger()
}
session, err := codespaces.ConnectToLiveshare(ctx, a.logger, debugLogger, a.apiClient, codespace)
session, err := codespaces.ConnectToLiveshare(ctx, a.logger, liveshareLogger, a.apiClient, codespace)
if err != nil {
return fmt.Errorf("error connecting to Live Share: %w", err)
}

View file

@ -75,10 +75,6 @@ func Connect(ctx context.Context, opts Options) (*Session, error) {
return nil, err
}
if opts.Logger == nil {
return nil, errors.New("Logger is required")
}
sock := newSocket(uri, opts.TLSConfig)
if err := sock.connect(ctx); err != nil {
return nil, fmt.Errorf("error connecting websocket: %w", err)