completer: remove useless logger parameter

Report the error to the user directly.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
This commit is contained in:
Robin Jarry 2022-07-11 11:11:36 +02:00
parent f5e886406b
commit f2dac06029
2 changed files with 17 additions and 12 deletions

View File

@ -4,7 +4,7 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"io" "io"
"log" "io/ioutil"
"mime" "mime"
"net/mail" "net/mail"
"os/exec" "os/exec"
@ -25,7 +25,6 @@ type Completer struct {
AddressBookCmd string AddressBookCmd string
errHandler func(error) errHandler func(error)
logger *log.Logger
} }
// A CompleteFunc accepts a string to be completed and returns a slice of // A CompleteFunc accepts a string to be completed and returns a slice of
@ -33,11 +32,10 @@ type Completer struct {
type CompleteFunc func(string) ([]string, string) type CompleteFunc func(string) ([]string, string)
// New creates a new Completer with the specified address book command. // New creates a new Completer with the specified address book command.
func New(addressBookCmd string, errHandler func(error), logger *log.Logger) *Completer { func New(addressBookCmd string, errHandler func(error)) *Completer {
return &Completer{ return &Completer{
AddressBookCmd: addressBookCmd, AddressBookCmd: addressBookCmd,
errHandler: errHandler, errHandler: errHandler,
logger: logger,
} }
} }
@ -86,20 +84,27 @@ func (c *Completer) completeAddress(s string) ([]string, string, error) {
if err != nil { if err != nil {
return nil, "", fmt.Errorf("stdout: %v", err) return nil, "", fmt.Errorf("stdout: %v", err)
} }
stderr, err := cmd.StderrPipe()
if err != nil {
return nil, "", fmt.Errorf("stderr: %v", err)
}
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
return nil, "", fmt.Errorf("cmd start: %v", err) return nil, "", fmt.Errorf("cmd start: %v", err)
} }
completions, err := readCompletions(stdout)
if err != nil {
return nil, "", fmt.Errorf("read completions: %v", err)
}
// Wait returns an error if the exit status != 0, which some completion // Wait returns an error if the exit status != 0, which some completion
// programs will do to signal no matches. We don't want to spam the user with // programs will do to signal no matches. We don't want to spam the user with
// spurious error messages, so we'll ignore any errors that arise at this // spurious error messages, so we'll ignore any errors that arise at this
// point. // point.
if err := cmd.Wait(); err != nil { defer cmd.Wait()
c.logger.Printf("completion error: %v", err)
completions, err := readCompletions(stdout)
if err != nil {
buf, _ := ioutil.ReadAll(stderr)
msg := strings.TrimSpace(string(buf))
if msg != "" {
msg = ": " + msg
}
return nil, "", fmt.Errorf("read completions%s: %v", msg, err)
} }
return completions, prefix, nil return completions, prefix, nil

View File

@ -86,7 +86,7 @@ func NewComposer(aerc *Aerc, acct *AccountView, conf *config.AercConfig,
aerc.PushError( aerc.PushError(
fmt.Sprintf("could not complete header: %v", err)) fmt.Sprintf("could not complete header: %v", err))
worker.Logger.Printf("could not complete header: %v", err) worker.Logger.Printf("could not complete header: %v", err)
}, aerc.Logger()) })
email, err := ioutil.TempFile("", "aerc-compose-*.eml") email, err := ioutil.TempFile("", "aerc-compose-*.eml")
if err != nil { if err != nil {