Skip to content

Commit

Permalink
Merge c392346 into bfef56a
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed May 6, 2019
2 parents bfef56a + c392346 commit 1f9362c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion processor/file.go
Expand Up @@ -80,7 +80,15 @@ func walkDirectoryParallel(root string, output chan *FileJob) {
var all []os.FileInfo
// clean path including trailing slashes
root = filepath.Clean(root)
target, _ := os.Lstat(root)
target, err := os.Lstat(root)

if err != nil {
// This error is non-recoverable due to user input so hard crash
printError(err.Error())
os.Exit(1)
return
}

if !target.IsDir() {
// create an array with a single FileInfo
all = append(all, target)
Expand Down
6 changes: 6 additions & 0 deletions processor/formatters.go
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
glang "golang.org/x/text/language"
gmessage "golang.org/x/text/message"
"os"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -528,3 +529,8 @@ func printTrace(msg string) {
fmt.Println(fmt.Sprintf("TRACE %s: %s", getFormattedTime(), msg))
}
}

// Used when explicitly for os.exit output when crashing out
func printError(msg string) {
_, _ = fmt.Fprintf(os.Stderr, "ERROR %s: %s", getFormattedTime(), msg)
}
4 changes: 4 additions & 0 deletions processor/formatters_test.go
Expand Up @@ -26,6 +26,10 @@ func TestPrintWarn(t *testing.T) {
printWarn("Testing print warn")
}

func TestPrintError(t *testing.T) {
printError("Testing print error")
}

func TestGetFormattedTime(t *testing.T) {
res := getFormattedTime()

Expand Down

0 comments on commit 1f9362c

Please sign in to comment.