Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Send stderr to ioutil.discard and log more human readable error #14

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cmd/coder/sync.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -28,6 +29,9 @@ func (cmd *syncCmd) RegisterFlags(fl *pflag.FlagSet) {
fl.BoolVarP(&cmd.init, "init", "i", false, "do inititial transfer and exit")
}

// See https://lxadm.com/Rsync_exit_codes#List_of_standard_rsync_exit_codes.
var NoRsync = errors.New("rsync: exit status 2")

func (cmd *syncCmd) Run(fl *pflag.FlagSet) {
var (
local = fl.Arg(0)
Expand All @@ -49,7 +53,7 @@ func (cmd *syncCmd) Run(fl *pflag.FlagSet) {

remoteTokens := strings.SplitN(remote, ":", 2)
if len(remoteTokens) != 2 {
flog.Fatal("remote misformmated")
flog.Fatal("remote misformatted")
}
var (
envName = remoteTokens[0]
Expand All @@ -73,5 +77,10 @@ func (cmd *syncCmd) Run(fl *pflag.FlagSet) {
for err == nil || err == sync.ErrRestartSync {
err = s.Run()
}
flog.Fatal("sync: %v", err)

if err == NoRsync {
flog.Fatal("no compatible rsync present on remote machine")
} else {
flog.Fatal("sync: %v", err)
}
}
4 changes: 2 additions & 2 deletions internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -56,7 +57,7 @@ func (s Sync) syncPaths(delete bool, local, remote string) error {
// good in general for codebases.
cmd := exec.Command("rsync", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stderr = ioutil.Discard
cmd.Stdin = os.Stdin
err := cmd.Run()
if err != nil {
Expand Down Expand Up @@ -248,7 +249,6 @@ func (s Sync) Run() error {
return nil
}


flog.Info("watching %s for changes", s.LocalDir)

var droppedEvents uint64
Expand Down