sojuctl: don't use log.Fatalf in readPassword

This commit is contained in:
Simon Ser 2021-04-19 14:11:25 +02:00
parent 0d6d297027
commit c994ce7092

View file

@ -4,6 +4,7 @@ import (
"bufio"
"flag"
"fmt"
"io"
"log"
"os"
@ -125,12 +126,13 @@ func readPassword() ([]byte, error) {
fmt.Printf("\n")
} else {
fmt.Fprintf(os.Stderr, "Warning: Reading password from stdin.\n")
// TODO: the buffering messes up repeated calls to readPassword
scanner := bufio.NewScanner(os.Stdin)
if !scanner.Scan() {
if err := scanner.Err(); err != nil {
log.Fatalf("failed to read password from stdin: %v", err)
return nil, err
}
log.Fatalf("failed to read password from stdin: stdin is empty")
return nil, io.ErrUnexpectedEOF
}
password = scanner.Bytes()