summaryrefslogtreecommitdiffstats
path: root/pkg/gui/confirmation_panel.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-12-16 17:05:34 +1100
committerJesse Duffield <jessedduffield@gmail.com>2018-12-16 17:28:04 +1100
commit4886b8350e0af56fd1d634c99e0f7502f23b9289 (patch)
tree860e1bb69071d918dcbd0e9083d893eef56b4142 /pkg/gui/confirmation_panel.go
parentaf26b5f3e0779fb218bb77506fbcd7da964942fe (diff)
always hide rather than delete the credentials view, and don't log on error in case there is a user password in the error
Diffstat (limited to 'pkg/gui/confirmation_panel.go')
-rw-r--r--pkg/gui/confirmation_panel.go34
1 files changed, 22 insertions, 12 deletions
diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go
index 99455a30c..cdb01466a 100644
--- a/pkg/gui/confirmation_panel.go
+++ b/pkg/gui/confirmation_panel.go
@@ -89,6 +89,7 @@ func (gui *Gui) onNewPopupPanel() {
_, _ = gui.g.SetViewOnBottom("credentials")
}
+// it is very important that within this function we never include the original prompt in any error messages, because it may contain e.g. a user password
func (gui *Gui) createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, title, prompt string, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error {
gui.onNewPopupPanel()
g.Update(func(g *gocui.Gui) error {
@@ -138,18 +139,27 @@ func (gui *Gui) createMessagePanel(g *gocui.Gui, currentView *gocui.View, title,
return gui.createConfirmationPanel(g, currentView, title, prompt, nil, nil)
}
-func (gui *Gui) createErrorPanel(g *gocui.Gui, message string) error {
- go func() {
- // when reporting is switched on this log call sometimes introduces
- // a delay on the error panel popping up. Here I'm adding a second wait
- // so that the error is logged while the user is reading the error message
- time.Sleep(time.Second)
- gui.Log.Error(message)
- }()
-
- // gui.Log.WithField("staging", "staging").Info("creating confirmation panel")
- currentView := g.CurrentView()
+// createSpecificErrorPanel allows you to create an error popup, specifying the
+// view to be focused when the user closes the popup, and a boolean specifying
+// whether we will log the error. If the message may include a user password,
+// this function is to be used over the more generic createErrorPanel, with
+// willLog set to false
+func (gui *Gui) createSpecificErrorPanel(message string, nextView *gocui.View, willLog bool) error {
+ if willLog {
+ go func() {
+ // when reporting is switched on this log call sometimes introduces
+ // a delay on the error panel popping up. Here I'm adding a second wait
+ // so that the error is logged while the user is reading the error message
+ time.Sleep(time.Second)
+ gui.Log.Error(message)
+ }()
+ }
+
colorFunction := color.New(color.FgRed).SprintFunc()
coloredMessage := colorFunction(strings.TrimSpace(message))
- return gui.createConfirmationPanel(g, currentView, gui.Tr.SLocalize("Error"), coloredMessage, nil, nil)
+ return gui.createConfirmationPanel(gui.g, nextView, gui.Tr.SLocalize("Error"), coloredMessage, nil, nil)
+}
+
+func (gui *Gui) createErrorPanel(g *gocui.Gui, message string) error {
+ return gui.createSpecificErrorPanel(message, g.CurrentView(), true)
}