diff --git a/main.go b/main.go index bedf8393..8c673f06 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "runtime" + "github.com/docker/docker/client" "github.com/go-errors/errors" "github.com/jesseduffield/lazydocker/pkg/app" "github.com/jesseduffield/lazydocker/pkg/config" @@ -50,6 +51,11 @@ func main() { } if err != nil { + if client.IsErrConnectionFailed(err) { + log.Println(app.Tr.ConnectionFailed) + os.Exit(0) + } + newErr := errors.Wrap(err, 0) stackTrace := newErr.ErrorStack() app.Log.Error(stackTrace) diff --git a/pkg/commands/container.go b/pkg/commands/container.go index 614bac45..e2d3b5a4 100644 --- a/pkg/commands/container.go +++ b/pkg/commands/container.go @@ -283,7 +283,7 @@ func (c *Container) GetDisplayCPUPerc() string { percentage, err := strconv.ParseFloat(strings.TrimSuffix(stats.CPUPerc, "%"), 32) if err != nil { - c.Log.Error(err) + // probably complaining about not being able to convert '--' return "" } diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index fc337bc6..254569e1 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -182,7 +182,7 @@ func GetDefaultConfig() UserConfig { StopService: "{{ .DockerCompose }} stop {{ .Service.Name }}", ServiceLogs: "{{ .DockerCompose }} logs --since=60m --follow {{ .Service.Name }}", ViewServiceLogs: "{{ .DockerCompose }} logs --follow {{ .Service.Name }}", - AllLogs: "{{ .DockerCompose }} logs --since=60m --follow", + AllLogs: "{{ .DockerCompose }} logs --tail=300 --follow", ViewAllLogs: "{{ .DockerCompose }} logs", DockerComposeConfig: "{{ .DockerCompose }} config", CheckDockerComposeConfig: "{{ .DockerCompose }} config --quiet", diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 3f684c3e..6fda5f27 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -202,7 +202,11 @@ func (gui *Gui) renderLogs(container *commands.Container, template string, setup return gui.T.NewTickerTask(time.Millisecond*200, nil, func(stop, notifyStopped chan struct{}) { gui.clearMainView() - cmd := container.TTYLogsCommand() + command := utils.ApplyTemplate( + template, + gui.DockerCommand.NewCommandObject(commands.CommandObject{Container: container}), + ) + cmd := gui.OSCommand.RunCustomCommand(command) setup(cmd) @@ -211,6 +215,7 @@ func (gui *Gui) renderLogs(container *commands.Container, template string, setup go func() { <-stop cmd.Process.Kill() + gui.Log.Info("killed container logs process") return }() diff --git a/pkg/gui/services_panel.go b/pkg/gui/services_panel.go index b2dfb5e6..e7cc5361 100644 --- a/pkg/gui/services_panel.go +++ b/pkg/gui/services_panel.go @@ -137,15 +137,11 @@ func (gui *Gui) renderServiceLogs(service *commands.Service) error { } if service.Container == nil { - gui.Log.Warn("container is nil") return gui.T.NewTask(func(stop chan struct{}) { - gui.Log.Warn("about to clear main view") gui.clearMainView() - gui.Log.Warn("cleared main view") }) } - gui.Log.Warn("about to render container logs for service ", service.Name) return gui.renderContainerLogs(service.Container) } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index f6914e97..833d8577 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -20,6 +20,7 @@ type TranslationSet struct { AnonymousReportingPrompt string ConfirmQuit string ErrorOccurred string + ConnectionFailed string Donate string Cancel string CustomCommandTitle string @@ -84,9 +85,10 @@ func englishSet() TranslationSet { RunningSubprocess: "running subprocess", NoViewMachingNewLineFocusedSwitchStatement: "No view matching newLineFocused switch statement", - ErrorOccurred: "An error occurred! Please create an issue at https://github.com/jesseduffield/lazydocker/issues", - Donate: "Donate", - Confirm: "Confirm", + ErrorOccurred: "An error occurred! Please create an issue at https://github.com/jesseduffield/lazydocker/issues", + ConnectionFailed: "connection to docker client failed. You may need to restart the docker client", + Donate: "Donate", + Confirm: "Confirm", Navigate: "navigate", Execute: "execute", diff --git a/pkg/tasks/tasks.go b/pkg/tasks/tasks.go index 3bbfb106..1d84c4ac 100644 --- a/pkg/tasks/tasks.go +++ b/pkg/tasks/tasks.go @@ -45,7 +45,9 @@ func (t *TaskManager) NewTask(f func(stop chan struct{})) error { notifyStopped := make(chan struct{}) if t.currentTask != nil { + t.Log.Info("asking task to stop") t.currentTask.Stop() + t.Log.Info("task stopped") } t.currentTask = &Task{ @@ -57,6 +59,7 @@ func (t *TaskManager) NewTask(f func(stop chan struct{})) error { go func() { f(stop) + t.Log.Info("returned from function, closing notifyStopped") close(notifyStopped) }() }() @@ -66,14 +69,17 @@ func (t *TaskManager) NewTask(f func(stop chan struct{})) error { func (t *Task) Stop() { close(t.stop) + t.Log.Info("closed stop channel, waiting for notifyStopped message") <-t.notifyStopped + t.Log.Info("received notifystopped message") return } // NewTickerTask is a convenience function for making a new task that repeats some action once per e.g. second // the before function gets called after the lock is obtained, but before the ticker starts. +// if you handle a message on the stop channel in f() you need to send a message on the notifyStopped channel because returning is not sufficient. Here, unlike in a regular task, simply returning means we're now going to wait till the next tick to run again. func (t *TaskManager) NewTickerTask(duration time.Duration, before func(stop chan struct{}), f func(stop, notifyStopped chan struct{})) error { - notifyStopped := make(chan struct{}) + notifyStopped := make(chan struct{}, 10) return t.NewTask(func(stop chan struct{}) { if before != nil { @@ -81,14 +87,17 @@ func (t *TaskManager) NewTickerTask(duration time.Duration, before func(stop cha } tickChan := time.NewTicker(duration) // calling f first so that we're not waiting for the first tick - f(stop, notifyStopped) + // f(stop, notifyStopped) for { select { case <-notifyStopped: + t.Log.Info("exiting ticker task due to notifyStopped channel") return case <-stop: + t.Log.Info("exiting ticker task due to stopped cahnnel") return case <-tickChan.C: + t.Log.Info("running ticker task again") f(stop, notifyStopped) } } diff --git a/test/testmain/main.go b/test/testmain/main.go index cb825708..3a9d579b 100644 --- a/test/testmain/main.go +++ b/test/testmain/main.go @@ -1,9 +1,21 @@ package main -import "fmt" +import "log" func main() { - var arr []string - arr = nil - fmt.Println(len(arr)) + c := make(chan struct{}) + + close(c) + + close(c) + + select { + case <-c: + log.Println("hmm") + } + + select { + case <-c: + log.Println("okay") + } }