git » chasquid » commit 9fe790d

aliases: Log the "alias-exists" hook output, for debugging

author Alberto Bertogli
2020-05-22 13:40:58 UTC
committer Alberto Bertogli
2020-05-22 13:43:28 UTC
parent bee7a9f193dd75545a5ca5249f7beeb8f1bf1e76

aliases: Log the "alias-exists" hook output, for debugging

The output of the alias-exists hook is unused, so currently it's
discarded silently.

However, it can be very useful to debug issues when the hook is not
working as expected.

So this patch makes chasquid log the combined output (stdout and stderr)
to the execution trace.

internal/aliases/aliases.go +4 -1

diff --git a/internal/aliases/aliases.go b/internal/aliases/aliases.go
index df2e1f7..fc29951 100644
--- a/internal/aliases/aliases.go
+++ b/internal/aliases/aliases.go
@@ -453,12 +453,15 @@ func (v *Resolver) runExistsHook(addr string) bool {
 	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
 	defer cancel()
 	cmd := exec.CommandContext(ctx, v.ExistsHook, addr)
-	err := cmd.Run()
+	out, err := cmd.CombinedOutput()
+	tr.Debugf("output: %q", string(out))
 	if err != nil {
 		tr.Debugf("not exists: %v", err)
 		hookResults.Add("exists:false", 1)
 		return false
 	hookResults.Add("exists:true", 1)
 	return true