Skip to content

Commit

Permalink
Catch stderr from the invoked osascript
Browse files Browse the repository at this point in the history
If an error occurs, print the error message from stderr.
  • Loading branch information
dehanj committed Nov 18, 2024
1 parent 8d91cb8 commit 79cdf63
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/tkey-ssh-agent/pinentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"bufio"
"bytes"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -144,8 +145,16 @@ func macOSPrompt(msg, title string) (string, error) {

c := exec.Command("osascript", "-s", "se", "-l", "JavaScript")
c.Stdin = script

stderror := new(bytes.Buffer)
c.Stderr = stderror

out, err := c.Output()
if err != nil {
scanner := bufio.NewScanner(stderror)
for scanner.Scan() {
le.Printf("osascript stderr: %s\n", scanner.Text())
}
return "", fmt.Errorf("failed to execute osascript: %w", err)
}
var x struct {
Expand Down

0 comments on commit 79cdf63

Please sign in to comment.