mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-21 23:01:03 +00:00
don't panick on unix connection failure
This commit is contained in:
parent
51d9b14ab5
commit
ba426f05be
3 changed files with 36 additions and 1 deletions
5
main.go
5
main.go
|
|
@ -55,6 +55,11 @@ func main() {
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
if errMessage, known := app.KnownError(err); known {
|
||||
log.Println(errMessage)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if client.IsErrConnectionFailed(err) {
|
||||
log.Println(app.Tr.ConnectionFailed)
|
||||
os.Exit(0)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package app
|
|||
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazydocker/pkg/commands"
|
||||
"github.com/jesseduffield/lazydocker/pkg/config"
|
||||
|
|
@ -50,7 +51,9 @@ func NewApp(config *config.AppConfig) (*App, error) {
|
|||
}
|
||||
|
||||
func (app *App) Run() error {
|
||||
return app.Gui.RunWithSubprocesses()
|
||||
err := app.Gui.RunWithSubprocesses()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Close closes any resources
|
||||
|
|
@ -63,3 +66,28 @@ func (app *App) Close() error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type errorMapping struct {
|
||||
originalError string
|
||||
newError string
|
||||
}
|
||||
|
||||
// KnownError takes an error and tells us whether it's an error that we know about where we can print a nicely formatted version of it rather than panicking with a stack trace
|
||||
func (app *App) KnownError(err error) (string, bool) {
|
||||
errorMessage := err.Error()
|
||||
|
||||
mappings := []errorMapping{
|
||||
{
|
||||
originalError: "Got permission denied while trying to connect to the Docker daemon socket",
|
||||
newError: app.Tr.CannotAccessDockerSocketError,
|
||||
},
|
||||
}
|
||||
|
||||
for _, mapping := range mappings {
|
||||
if strings.Contains(errorMessage, mapping.originalError) {
|
||||
return mapping.newError, true
|
||||
}
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ type TranslationSet struct {
|
|||
ConnectionFailed string
|
||||
UnattachableContainerError string
|
||||
CannotAttachStoppedContainerError string
|
||||
CannotAccessDockerSocketError string
|
||||
|
||||
Donate string
|
||||
Cancel string
|
||||
|
|
@ -98,6 +99,7 @@ func englishSet() TranslationSet {
|
|||
ConnectionFailed: "connection to docker client failed. You may need to restart the docker client",
|
||||
UnattachableContainerError: "Container does not support attaching. You must either run the service with the '-it' flag or use `stdin_open: true, tty: true` in the docker-compose.yml file",
|
||||
CannotAttachStoppedContainerError: "You cannot attach to a stopped container, you need to start it first (which you can actually do with the 'r' key) (yes I'm too lazy to do this automatically for you) (pretty cool that I get to communicate one-on-one with you in the form of an error message though)",
|
||||
CannotAccessDockerSocketError: "Can't access docker socket at: unix:///var/run/docker.sock\nRun lazydocker as root or read https://docs.docker.com/install/linux/linux-postinstall/",
|
||||
|
||||
Donate: "Donate",
|
||||
Confirm: "Confirm",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue