summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-07-11 11:11:36 +0200
committerRobin Jarry <robin@jarry.cc>2022-07-17 19:00:35 +0200
commitf2dac06029a273aa8d5bcfc24102e113b29138be (patch)
tree5cbd5c080de4ac3497a983bcc4d9fa6c66f3a7ed
parentf5e886406bd6ac54695947891156e37dae314a37 (diff)
downloadaerc-f2dac06029a273aa8d5bcfc24102e113b29138be.zip
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>
-rw-r--r--completer/completer.go27
-rw-r--r--widgets/compose.go2
2 files changed, 17 insertions, 12 deletions
diff --git a/completer/completer.go b/completer/completer.go
index 251658e..83a9c12 100644
--- a/completer/completer.go
+++ b/completer/completer.go
@@ -4,7 +4,7 @@ import (
"bufio"
"fmt"
"io"
- "log"
+ "io/ioutil"
"mime"
"net/mail"
"os/exec"
@@ -25,7 +25,6 @@ type Completer struct {
AddressBookCmd string
errHandler func(error)
- logger *log.Logger
}
// 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)
// 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{
AddressBookCmd: addressBookCmd,
errHandler: errHandler,
- logger: logger,
}
}
@@ -86,20 +84,27 @@ func (c *Completer) completeAddress(s string) ([]string, string, error) {
if err != nil {
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 {
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
// 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
// point.
- if err := cmd.Wait(); err != nil {
- c.logger.Printf("completion error: %v", err)
+ defer cmd.Wait()
+
+ 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
diff --git a/widgets/compose.go b/widgets/compose.go
index 2516c48..465a733 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -86,7 +86,7 @@ func NewComposer(aerc *Aerc, acct *AccountView, conf *config.AercConfig,
aerc.PushError(
fmt.Sprintf("could not complete header: %v", err))
worker.Logger.Printf("could not complete header: %v", err)
- }, aerc.Logger())
+ })
email, err := ioutil.TempFile("", "aerc-compose-*.eml")
if err != nil {