Skip to content

Commit 037493d

Browse files
committed
Error Handling when TERM variable is invalid
1 parent cb2b5c3 commit 037493d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

pkg/app/errors.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package app
22

33
import (
4+
"fmt"
5+
"os"
46
"strings"
57

68
"github.com/jesseduffield/lazygit/pkg/i18n"
@@ -31,6 +33,14 @@ func knownError(tr *i18n.TranslationSet, err error) (string, bool) {
3133
originalError: "getwd: no such file or directory",
3234
newError: tr.WorkingDirectoryDoesNotExist,
3335
},
36+
{
37+
originalError: "terminal entry not found: term not set",
38+
newError: tr.TermNotSet,
39+
},
40+
{
41+
originalError: "$TERM Not Found",
42+
newError: fmt.Sprintf(tr.TermNotFound, os.Getenv("TERM")),
43+
},
3444
}
3545

3646
if mapping, ok := lo.Find(mappings, func(mapping errorMapping) bool {

pkg/gui/gui.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,9 @@ func (gui *Gui) initGocui(headless bool, test integrationTypes.IntegrationTest)
758758
Height: height,
759759
})
760760
if err != nil {
761+
if err.Error() == "exit status 1" {
762+
err = errors.New("$TERM Not Found")
763+
}
761764
return nil, err
762765
}
763766

pkg/i18n/english.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ type TranslationSet struct {
499499
StashOptions string
500500
NotARepository string
501501
WorkingDirectoryDoesNotExist string
502+
TermNotSet string
503+
TermNotFound string
502504
ScrollLeft string
503505
ScrollRight string
504506
DiscardPatch string
@@ -1583,6 +1585,8 @@ func EnglishTranslationSet() *TranslationSet {
15831585
StashOptions: "Stash options",
15841586
NotARepository: "Error: must be run inside a git repository",
15851587
WorkingDirectoryDoesNotExist: "Error: the current working directory does not exist",
1588+
TermNotSet: "Error: TERM environment variable not set.",
1589+
TermNotFound: "Error: could not find terminal info for $TERM '%s'. Please check your TERM variable is set correctly.",
15861590
ScrollLeft: "Scroll left",
15871591
ScrollRight: "Scroll right",
15881592
DiscardPatch: "Discard patch",

0 commit comments

Comments
 (0)