aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuey-Liang Kao <s101062801@m101.nthu.edu.tw>2017-01-20 12:40:12 -0600
committerGitHub <noreply@github.com>2017-01-20 12:40:12 -0600
commit9edce9ad2c7cca5dc60cff8ce45a9855ab719365 (patch)
tree563c75d07877de03334d612a661413b9fd703725
parentde346783c83061b2b88e5b158f6a659d569f206e (diff)
parente81c005dd64e7f206bfe5d2dd2bccc295b45fb9e (diff)
Merge pull request #22 from NonerKao/issue/output-no-panic
Makes all output messages consistent
-rw-r--r--todolist/formatter.go4
-rw-r--r--todolist/parser.go7
2 files changed, 9 insertions, 2 deletions
diff --git a/todolist/formatter.go b/todolist/formatter.go
index b259f6a..db4aa4b 100644
--- a/todolist/formatter.go
+++ b/todolist/formatter.go
@@ -62,7 +62,9 @@ func (f *Formatter) formatDue(due string) string {
dueTime, err := time.Parse("2006-01-02", due)
if err != nil {
- panic(err)
+ fmt.Println(err)
+ fmt.Println("This may due to the corruption of .todos.json file.")
+ os.Exit(-1)
}
if isToday(dueTime) {
diff --git a/todolist/parser.go b/todolist/parser.go
index 767785b..62d864d 100644
--- a/todolist/parser.go
+++ b/todolist/parser.go
@@ -2,6 +2,7 @@ package todolist
import (
"fmt"
+ "os"
"regexp"
"strconv"
"strings"
@@ -116,7 +117,11 @@ func (p *Parser) parseArbitraryDateWithYear(_date string, year int) time.Time {
if date, err := time.Parse("2 Jan 2006", res); err == nil {
return date
}
- panic(fmt.Errorf("Could not parse the date you gave me: '%s'", _date))
+ fmt.Printf("Could not parse the date you gave me: %s\n", _date)
+ fmt.Println("I'm expecting a date like \"Dec 22\" or \"22 Dec\".")
+ fmt.Println("See http://todolist.site/#adding for more info.")
+ os.Exit(-1)
+ return time.Now()
}
func (p *Parser) monday(day time.Time) string {