From 037493db80786e54e927eecbc3b7312fcc8193a2 Mon Sep 17 00:00:00 2001 From: Seno Pamungkas Date: Sat, 20 Sep 2025 22:05:42 +0700 Subject: [PATCH] Error Handling when TERM variable is invalid --- pkg/app/errors.go | 10 ++++++++++ pkg/gui/gui.go | 3 +++ pkg/i18n/english.go | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/pkg/app/errors.go b/pkg/app/errors.go index 506fec276e2..f917a61b87d 100644 --- a/pkg/app/errors.go +++ b/pkg/app/errors.go @@ -1,6 +1,8 @@ package app import ( + "fmt" + "os" "strings" "github.com/jesseduffield/lazygit/pkg/i18n" @@ -31,6 +33,14 @@ func knownError(tr *i18n.TranslationSet, err error) (string, bool) { originalError: "getwd: no such file or directory", newError: tr.WorkingDirectoryDoesNotExist, }, + { + originalError: "terminal entry not found: term not set", + newError: tr.TermNotSet, + }, + { + originalError: "$TERM Not Found", + newError: fmt.Sprintf(tr.TermNotFound, os.Getenv("TERM")), + }, } if mapping, ok := lo.Find(mappings, func(mapping errorMapping) bool { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index c9252e03d60..430e91808b2 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -758,6 +758,9 @@ func (gui *Gui) initGocui(headless bool, test integrationTypes.IntegrationTest) Height: height, }) if err != nil { + if err.Error() == "exit status 1" { + err = errors.New("$TERM Not Found") + } return nil, err } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index d162d20dc20..1cc76af6404 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -499,6 +499,8 @@ type TranslationSet struct { StashOptions string NotARepository string WorkingDirectoryDoesNotExist string + TermNotSet string + TermNotFound string ScrollLeft string ScrollRight string DiscardPatch string @@ -1583,6 +1585,8 @@ func EnglishTranslationSet() *TranslationSet { StashOptions: "Stash options", NotARepository: "Error: must be run inside a git repository", WorkingDirectoryDoesNotExist: "Error: the current working directory does not exist", + TermNotSet: "Error: TERM environment variable not set.", + TermNotFound: "Error: could not find terminal info for $TERM '%s'. Please check your TERM variable is set correctly.", ScrollLeft: "Scroll left", ScrollRight: "Scroll right", DiscardPatch: "Discard patch",