Skip to content

Commit

Permalink
Makes errors be written to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
tomnomnom committed Sep 16, 2018
1 parent 0e8c165 commit 6a7c4a7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func main() {

homeDir, err := getHomeDir()
if err != nil {
fmt.Println("unable to open user's home directory")
fmt.Fprintln(os.Stderr, "unable to open user's home directory")
return
}

filename := fmt.Sprintf("%s/.gf/%s.json", homeDir, patName)
f, err := os.Open(filename)
if err != nil {
fmt.Println("no such pattern")
fmt.Fprintln(os.Stderr, "no such pattern")
return
}
defer f.Close()
Expand All @@ -42,7 +42,12 @@ func main() {
err = dec.Decode(&pat)

if err != nil {
fmt.Printf("pattern file '%s' is malformed: %s\n", filename, err)
fmt.Fprintf(os.Stderr, "pattern file '%s' is malformed: %s\n", filename, err)
return
}

if pat.Pattern == "" {
fmt.Fprintf(os.Stderr, "pattern file '%s' contains no pattern\n", filename)
return
}

Expand Down

0 comments on commit 6a7c4a7

Please sign in to comment.