Update error checking on fmt.Fprint* after errcheck update

Now we need to check or ignore errors on fmt.Fprint* explicitly -
previously errcheck just ignored them for us.
This commit is contained in:
Nick Craig-Wood 2018-05-22 09:41:13 +01:00
parent a38f8b87ce
commit 512f4b4487
9 changed files with 24 additions and 24 deletions

View File

@ -340,7 +340,7 @@ func NewFs(name, root string) (fs.Fs, error) {
// Ask for password if none was defined and we're allowed to // Ask for password if none was defined and we're allowed to
if pass == "" && *sftpAskPassword { if pass == "" && *sftpAskPassword {
fmt.Fprint(os.Stderr, "Enter SFTP password: ") _, _ = fmt.Fprint(os.Stderr, "Enter SFTP password: ")
clearpass := config.ReadPassword() clearpass := config.ReadPassword()
sshConfig.Auth = append(sshConfig.Auth, ssh.Password(clearpass)) sshConfig.Auth = append(sshConfig.Auth, ssh.Password(clearpass))
} }

View File

@ -122,7 +122,7 @@ func runRoot(cmd *cobra.Command, args []string) {
resolveExitCode(nil) resolveExitCode(nil)
} else { } else {
_ = Root.Usage() _ = Root.Usage()
fmt.Fprintf(os.Stderr, "Command not found.\n") _, _ = fmt.Fprintf(os.Stderr, "Command not found.\n")
resolveExitCode(errorCommandNotFound) resolveExitCode(errorCommandNotFound)
} }
} }
@ -368,12 +368,12 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
func CheckArgs(MinArgs, MaxArgs int, cmd *cobra.Command, args []string) { func CheckArgs(MinArgs, MaxArgs int, cmd *cobra.Command, args []string) {
if len(args) < MinArgs { if len(args) < MinArgs {
_ = cmd.Usage() _ = cmd.Usage()
fmt.Fprintf(os.Stderr, "Command %s needs %d arguments minimum\n", cmd.Name(), MinArgs) _, _ = fmt.Fprintf(os.Stderr, "Command %s needs %d arguments minimum\n", cmd.Name(), MinArgs)
// os.Exit(1) // os.Exit(1)
resolveExitCode(errorNotEnoughArguments) resolveExitCode(errorNotEnoughArguments)
} else if len(args) > MaxArgs { } else if len(args) > MaxArgs {
_ = cmd.Usage() _ = cmd.Usage()
fmt.Fprintf(os.Stderr, "Command %s needs %d arguments maximum\n", cmd.Name(), MaxArgs) _, _ = fmt.Fprintf(os.Stderr, "Command %s needs %d arguments maximum\n", cmd.Name(), MaxArgs)
// os.Exit(1) // os.Exit(1)
resolveExitCode(errorTooManyArguents) resolveExitCode(errorTooManyArguents)
} }

View File

@ -186,7 +186,7 @@ func Lsf(fsrc fs.Fs, out io.Writer) error {
continue continue
} }
} }
fmt.Fprintln(out, list.Format(entry)) _, _ = fmt.Fprintln(out, list.Format(entry))
} }
return nil return nil
}) })

View File

@ -135,7 +135,7 @@ func Tree(fsrc fs.Fs, outFile io.Writer, opts *tree.Options) error {
if !opts.DirsOnly { if !opts.DirsOnly {
footer += fmt.Sprintf(", %d files", nf) footer += fmt.Sprintf(", %d files", nf)
} }
fmt.Fprintln(outFile, footer) _, _ = fmt.Fprintln(outFile, footer)
} }
return nil return nil
} }

View File

@ -62,7 +62,7 @@ func (s *StatsInfo) String() string {
speed = speed * 8 speed = speed * 8
} }
fmt.Fprintf(buf, ` _, _ = fmt.Fprintf(buf, `
Transferred: %10s (%s) Transferred: %10s (%s)
Errors: %10d Errors: %10d
Checks: %10d Checks: %10d
@ -80,10 +80,10 @@ Elapsed time: %10v
s.mu.RUnlock() s.mu.RUnlock()
if !s.checking.empty() { if !s.checking.empty() {
fmt.Fprintf(buf, "Checking:\n%s\n", s.checking) _, _ = fmt.Fprintf(buf, "Checking:\n%s\n", s.checking)
} }
if !s.transferring.empty() { if !s.transferring.empty() {
fmt.Fprintf(buf, "Transferring:\n%s\n", s.transferring) _, _ = fmt.Fprintf(buf, "Transferring:\n%s\n", s.transferring)
} }
return buf.String() return buf.String()
} }

View File

@ -275,7 +275,7 @@ func checkPassword(password string) (string, error) {
trimmedPassword := strings.TrimSpace(password) trimmedPassword := strings.TrimSpace(password)
// Warn user if password has leading+trailing whitespace // Warn user if password has leading+trailing whitespace
if len(password) != len(trimmedPassword) { if len(password) != len(trimmedPassword) {
fmt.Fprintln(os.Stderr, "Your password contains leading/trailing whitespace - in previous versions of rclone this was stripped") _, _ = fmt.Fprintln(os.Stderr, "Your password contains leading/trailing whitespace - in previous versions of rclone this was stripped")
} }
// Normalize to reduce weird variations. // Normalize to reduce weird variations.
password = norm.NFKC.String(password) password = norm.NFKC.String(password)
@ -287,15 +287,15 @@ func checkPassword(password string) (string, error) {
// GetPassword asks the user for a password with the prompt given. // GetPassword asks the user for a password with the prompt given.
func GetPassword(prompt string) string { func GetPassword(prompt string) string {
fmt.Fprintln(os.Stderr, prompt) _, _ = fmt.Fprintln(os.Stderr, prompt)
for { for {
fmt.Fprint(os.Stderr, "password:") _, _ = fmt.Fprint(os.Stderr, "password:")
password := ReadPassword() password := ReadPassword()
password, err := checkPassword(password) password, err := checkPassword(password)
if err == nil { if err == nil {
return password return password
} }
fmt.Fprintf(os.Stderr, "Bad password: %v\n", err) _, _ = fmt.Fprintf(os.Stderr, "Bad password: %v\n", err)
} }
} }
@ -324,7 +324,7 @@ func getConfigPassword(q string) {
if err == nil { if err == nil {
return return
} }
fmt.Fprintln(os.Stderr, "Error:", err) _, _ = fmt.Fprintln(os.Stderr, "Error:", err)
} }
} }
@ -382,9 +382,9 @@ func saveConfig() error {
return errors.Errorf("Failed to write temp config file: %v", err) return errors.Errorf("Failed to write temp config file: %v", err)
} }
} else { } else {
fmt.Fprintln(f, "# Encrypted rclone configuration File") _, _ = fmt.Fprintln(f, "# Encrypted rclone configuration File")
fmt.Fprintln(f, "") _, _ = fmt.Fprintln(f, "")
fmt.Fprintln(f, "RCLONE_ENCRYPT_V0:") _, _ = fmt.Fprintln(f, "RCLONE_ENCRYPT_V0:")
// Generate new nonce and write it to the start of the ciphertext // Generate new nonce and write it to the start of the ciphertext
var nonce [24]byte var nonce [24]byte

View File

@ -17,7 +17,7 @@ import (
// ReadPassword reads a password without echoing it to the terminal. // ReadPassword reads a password without echoing it to the terminal.
func ReadPassword() string { func ReadPassword() string {
line, err := terminal.ReadPassword(int(os.Stdin.Fd())) line, err := terminal.ReadPassword(int(os.Stdin.Fd()))
fmt.Fprintln(os.Stderr) _, _ = fmt.Fprintln(os.Stderr)
if err != nil { if err != nil {
log.Fatalf("Failed to read password: %v", err) log.Fatalf("Failed to read password: %v", err)
} }

View File

@ -337,13 +337,13 @@ func (dt DirTree) Prune(dirNames map[string]bool) error {
func (dt DirTree) String() string { func (dt DirTree) String() string {
out := new(bytes.Buffer) out := new(bytes.Buffer)
for _, dir := range dt.Dirs() { for _, dir := range dt.Dirs() {
fmt.Fprintf(out, "%s/\n", dir) _, _ = fmt.Fprintf(out, "%s/\n", dir)
for _, entry := range dt[dir] { for _, entry := range dt[dir] {
flag := "" flag := ""
if _, ok := entry.(fs.Directory); ok { if _, ok := entry.(fs.Directory); ok {
flag = "/" flag = "/"
} }
fmt.Fprintf(out, " %s%s\n", path.Base(entry.Remote()), flag) _, _ = fmt.Fprintf(out, " %s%s\n", path.Base(entry.Remote()), flag)
} }
} }
return out.String() return out.String()

View File

@ -432,19 +432,19 @@ func (s *authServer) Start() {
state := req.FormValue("state") state := req.FormValue("state")
if state != s.state { if state != s.state {
fs.Debugf(nil, "State did not match: want %q got %q", s.state, state) fs.Debugf(nil, "State did not match: want %q got %q", s.state, state)
fmt.Fprintf(w, "<h1>Failure</h1>\n<p>Auth state doesn't match</p>") _, _ = fmt.Fprintf(w, "<h1>Failure</h1>\n<p>Auth state doesn't match</p>")
} else { } else {
fs.Debugf(nil, "Successfully got code") fs.Debugf(nil, "Successfully got code")
if s.code != nil { if s.code != nil {
fmt.Fprintf(w, "<h1>Success</h1>\n<p>Go back to rclone to continue</p>") _, _ = fmt.Fprintf(w, "<h1>Success</h1>\n<p>Go back to rclone to continue</p>")
} else { } else {
fmt.Fprintf(w, "<h1>Success</h1>\n<p>Cut and paste this code into rclone: <code>%s</code></p>", code) _, _ = fmt.Fprintf(w, "<h1>Success</h1>\n<p>Cut and paste this code into rclone: <code>%s</code></p>", code)
} }
} }
} else { } else {
fs.Debugf(nil, "No code found on request") fs.Debugf(nil, "No code found on request")
w.WriteHeader(500) w.WriteHeader(500)
fmt.Fprintf(w, "<h1>Failed!</h1>\nNo code found returned by remote server.") _, _ = fmt.Fprintf(w, "<h1>Failed!</h1>\nNo code found returned by remote server.")
} }
if s.code != nil { if s.code != nil {
s.code <- code s.code <- code