aboutsummaryrefslogtreecommitdiffstats
path: root/completer/completer.go
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 /completer/completer.go
parentf5e886406bd6ac54695947891156e37dae314a37 (diff)
downloadaerc-f2dac06029a273aa8d5bcfc24102e113b29138be.tar.gz
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>
Diffstat (limited to 'completer/completer.go')
-rw-r--r--completer/completer.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/completer/completer.go b/completer/completer.go
index 251658e6..83a9c125 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