mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
Merge pull request #14 from jesseduffield/12_unix-permission-error
don't panic on unix permission failure
This commit is contained in:
commit
da03778cf9
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 err != nil {
|
||||||
|
if errMessage, known := app.KnownError(err); known {
|
||||||
|
log.Println(errMessage)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if client.IsErrConnectionFailed(err) {
|
if client.IsErrConnectionFailed(err) {
|
||||||
log.Println(app.Tr.ConnectionFailed)
|
log.Println(app.Tr.ConnectionFailed)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazydocker/pkg/commands"
|
"github.com/jesseduffield/lazydocker/pkg/commands"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/config"
|
"github.com/jesseduffield/lazydocker/pkg/config"
|
||||||
|
|
@ -50,7 +51,9 @@ func NewApp(config *config.AppConfig) (*App, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) Run() error {
|
func (app *App) Run() error {
|
||||||
return app.Gui.RunWithSubprocesses()
|
err := app.Gui.RunWithSubprocesses()
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes any resources
|
// Close closes any resources
|
||||||
|
|
@ -63,3 +66,28 @@ func (app *App) Close() error {
|
||||||
}
|
}
|
||||||
return nil
|
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
|
ConnectionFailed string
|
||||||
UnattachableContainerError string
|
UnattachableContainerError string
|
||||||
CannotAttachStoppedContainerError string
|
CannotAttachStoppedContainerError string
|
||||||
|
CannotAccessDockerSocketError string
|
||||||
|
|
||||||
Donate string
|
Donate string
|
||||||
Cancel string
|
Cancel string
|
||||||
|
|
@ -98,6 +99,7 @@ func englishSet() TranslationSet {
|
||||||
ConnectionFailed: "connection to docker client failed. You may need to restart the docker client",
|
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",
|
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)",
|
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",
|
Donate: "Donate",
|
||||||
Confirm: "Confirm",
|
Confirm: "Confirm",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue