Get rid of the aerc.PushError(" " + $string) idiom

The individual callers should not be responsible for padding
This commit is contained in:
Reto Brunner 2021-01-30 13:51:32 +01:00
parent 949781fa0a
commit 8ea86cea41
18 changed files with 29 additions and 29 deletions

View file

@ -40,7 +40,7 @@ func (MakeDir) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushStatus("Directory created.", 10*time.Second) aerc.PushStatus("Directory created.", 10*time.Second)
acct.Directories().Select(name) acct.Directories().Select(name)
case *types.Error: case *types.Error:
aerc.PushError(" " + msg.Error.Error()) aerc.PushError(msg.Error.Error())
} }
}) })
return nil return nil

View file

@ -86,7 +86,7 @@ func (RemoveDir) Execute(aerc *widgets.Aerc, args []string) error {
case *types.Done: case *types.Done:
aerc.PushStatus("Directory removed.", 10*time.Second) aerc.PushStatus("Directory removed.", 10*time.Second)
case *types.Error: case *types.Error:
aerc.PushError(" " + msg.Error.Error()) aerc.PushError(msg.Error.Error())
case *types.Unsupported: case *types.Unsupported:
aerc.PushError(":rmdir is not supported by the backend.") aerc.PushError(":rmdir is not supported by the backend.")
} }

View file

@ -34,13 +34,13 @@ func (Attach) Execute(aerc *widgets.Aerc, args []string) error {
path, err := homedir.Expand(path) path, err := homedir.Expand(path)
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
return err return err
} }
pathinfo, err := os.Stat(path) pathinfo, err := os.Stat(path)
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
return err return err
} else if pathinfo.IsDir() { } else if pathinfo.IsDir() {
aerc.PushError("Attachment must be a file, not a directory") aerc.PushError("Attachment must be a file, not a directory")

View file

@ -63,7 +63,7 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
go func() { go func() {
errStr := <-errChan errStr := <-errChan
if errStr != "" { if errStr != "" {
aerc.PushError(" " + errStr) aerc.PushError(errStr)
return return
} }
@ -90,7 +90,7 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
r.Close() r.Close()
composer.Close() composer.Close()
case *types.Error: case *types.Error:
aerc.PushError(" " + msg.Error.Error()) aerc.PushError(msg.Error.Error())
r.Close() r.Close()
composer.Close() composer.Close()
} }

View file

@ -47,7 +47,7 @@ func (ExecCmd) Execute(aerc *widgets.Aerc, args []string) error {
go func() { go func() {
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
} else { } else {
if cmd.ProcessState.ExitCode() != 0 { if cmd.ProcessState.ExitCode() != 0 {
aerc.PushError(fmt.Sprintf( aerc.PushError(fmt.Sprintf(

View file

@ -86,7 +86,7 @@ func (Archive) Execute(aerc *widgets.Aerc, args []string) error {
case *types.Done: case *types.Done:
wg.Done() wg.Done()
case *types.Error: case *types.Error:
aerc.PushError(" " + msg.Error.Error()) aerc.PushError(msg.Error.Error())
success = false success = false
wg.Done() wg.Done()
} }

View file

@ -60,7 +60,7 @@ func (Copy) Execute(aerc *widgets.Aerc, args []string) error {
case *types.Done: case *types.Done:
aerc.PushStatus("Messages copied.", 10*time.Second) aerc.PushStatus("Messages copied.", 10*time.Second)
case *types.Error: case *types.Error:
aerc.PushError(" " + msg.Error.Error()) aerc.PushError(msg.Error.Error())
} }
}) })
return nil return nil

View file

@ -47,7 +47,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
case *types.Done: case *types.Done:
aerc.PushStatus("Messages deleted.", 10*time.Second) aerc.PushStatus("Messages deleted.", 10*time.Second)
case *types.Error: case *types.Error:
aerc.PushError(" " + msg.Error.Error()) aerc.PushError(msg.Error.Error())
case *types.Unsupported: case *types.Unsupported:
// notmuch doesn't support it, we want the user to know // notmuch doesn't support it, we want the user to know
aerc.PushError(" error, unsupported for this worker") aerc.PushError(" error, unsupported for this worker")

View file

@ -58,7 +58,7 @@ func (ModifyLabels) Execute(aerc *widgets.Aerc, args []string) error {
case *types.Done: case *types.Done:
aerc.PushStatus("labels updated", 10*time.Second) aerc.PushStatus("labels updated", 10*time.Second)
case *types.Error: case *types.Error:
aerc.PushError(" " + msg.Error.Error()) aerc.PushError(msg.Error.Error())
} }
}) })
return nil return nil

View file

@ -71,7 +71,7 @@ func (Move) Execute(aerc *widgets.Aerc, args []string) error {
case *types.Done: case *types.Done:
aerc.PushStatus("Message moved to "+joinedArgs, 10*time.Second) aerc.PushStatus("Message moved to "+joinedArgs, 10*time.Second)
case *types.Error: case *types.Error:
aerc.PushError(" " + msg.Error.Error()) aerc.PushError(msg.Error.Error())
} }
}) })
return nil return nil

View file

@ -75,7 +75,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
doTerm := func(reader io.Reader, name string) { doTerm := func(reader io.Reader, name string) {
term, err := commands.QuickTerm(aerc, cmd, reader) term, err := commands.QuickTerm(aerc, cmd, reader)
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
return return
} }
aerc.NewTab(term, name) aerc.NewTab(term, name)
@ -93,7 +93,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
}() }()
err = ecmd.Run() err = ecmd.Run()
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
} else { } else {
if ecmd.ProcessState.ExitCode() != 0 { if ecmd.ProcessState.ExitCode() != 0 {
aerc.PushError(fmt.Sprintf( aerc.PushError(fmt.Sprintf(

View file

@ -187,7 +187,7 @@ func submitFlagChange(aerc *widgets.Aerc, store *lib.MessageStore,
case *types.Done: case *types.Done:
wg.Done() wg.Done()
case *types.Error: case *types.Error:
aerc.PushError(" " + msg.Error.Error()) aerc.PushError(msg.Error.Error())
*success = false *success = false
wg.Done() wg.Done()
} }

View file

@ -86,7 +86,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
}, func(msg types.WorkerMessage) { }, func(msg types.WorkerMessage) {
switch msg := msg.(type) { switch msg := msg.(type) {
case *types.Error: case *types.Error:
aerc.PushError(" " + msg.Error.Error()) aerc.PushError(msg.Error.Error())
composer.Close() composer.Close()
} }
}) })

View file

@ -44,14 +44,14 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error {
tmpFile, err := ioutil.TempFile(os.TempDir(), "aerc-*"+extension) tmpFile, err := ioutil.TempFile(os.TempDir(), "aerc-*"+extension)
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
return return
} }
defer tmpFile.Close() defer tmpFile.Close()
_, err = io.Copy(tmpFile, reader) _, err = io.Copy(tmpFile, reader)
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
return return
} }
@ -68,7 +68,7 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error {
go func() { go func() {
err := xdg.Wait() err := xdg.Wait()
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
} }
}() }()

View file

@ -46,7 +46,7 @@ func TermCore(aerc *widgets.Aerc, args []string) error {
term.OnClose = func(err error) { term.OnClose = func(err error) {
aerc.RemoveTab(term) aerc.RemoveTab(term)
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
} }
} }
return nil return nil

View file

@ -32,7 +32,7 @@ func QuickTerm(aerc *widgets.Aerc, args []string, stdin io.Reader) (*widgets.Ter
term.OnClose = func(err error) { term.OnClose = func(err error) {
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
// remove the tab on error, otherwise it gets stuck // remove the tab on error, otherwise it gets stuck
aerc.RemoveTab(term) aerc.RemoveTab(term)
} else { } else {
@ -56,7 +56,7 @@ func QuickTerm(aerc *widgets.Aerc, args []string, stdin io.Reader) (*widgets.Ter
err := <-status err := <-status
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
} }
} }

View file

@ -428,7 +428,7 @@ func (wizard *AccountWizard) ConfigureTemporaryAccount(temporary bool) {
func (wizard *AccountWizard) errorFor(d ui.Interactive, err error) { func (wizard *AccountWizard) errorFor(d ui.Interactive, err error) {
if d == nil { if d == nil {
wizard.aerc.PushError(" " + err.Error()) wizard.aerc.PushError(err.Error())
wizard.Invalidate() wizard.Invalidate()
return return
} }
@ -443,7 +443,7 @@ func (wizard *AccountWizard) errorFor(d ui.Interactive, err error) {
wizard.step = step wizard.step = step
wizard.focus = focus wizard.focus = focus
wizard.Focus(true) wizard.Focus(true)
wizard.aerc.PushError(" " + err.Error()) wizard.aerc.PushError(err.Error())
wizard.Invalidate() wizard.Invalidate()
return return
} }
@ -559,7 +559,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
term.OnClose = func(err error) { term.OnClose = func(err error) {
wizard.aerc.RemoveTab(term) wizard.aerc.RemoveTab(term)
if err != nil { if err != nil {
wizard.aerc.PushError(" " + err.Error()) wizard.aerc.PushError(err.Error())
} }
} }
} }

View file

@ -429,11 +429,11 @@ func (aerc *Aerc) BeginExCommand(cmd string) {
exline := NewExLine(aerc.conf, cmd, func(cmd string) { exline := NewExLine(aerc.conf, cmd, func(cmd string) {
parts, err := shlex.Split(cmd) parts, err := shlex.Split(cmd)
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
} }
err = aerc.cmd(parts) err = aerc.cmd(parts)
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
} }
// only add to history if this is an unsimulated command, // only add to history if this is an unsimulated command,
// ie one not executed from a keybinding // ie one not executed from a keybinding
@ -457,7 +457,7 @@ func (aerc *Aerc) RegisterPrompt(prompt string, cmd []string) {
} }
err := aerc.cmd(cmd) err := aerc.cmd(cmd)
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
} }
}, func(cmd string) []string { }, func(cmd string) []string {
return nil // TODO: completions return nil // TODO: completions
@ -484,7 +484,7 @@ func (aerc *Aerc) RegisterChoices(choices []Choice) {
} }
err := aerc.cmd(cmd) err := aerc.cmd(cmd)
if err != nil { if err != nil {
aerc.PushError(" " + err.Error()) aerc.PushError(err.Error())
} }
}, func(cmd string) []string { }, func(cmd string) []string {
return nil // TODO: completions return nil // TODO: completions