From ed6ab22cbdbc475adf539637e45a67811ec0c15a Mon Sep 17 00:00:00 2001 From: Michael Strùˆder Date: Sat, 29 Apr 2017 16:31:31 +0200 Subject: display an error on malformed input --- todolist/parser.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'todolist/parser.go') diff --git a/todolist/parser.go b/todolist/parser.go index d55ab3b..38bdb7f 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -34,10 +34,14 @@ func (p Parser) Parse() (string, int, string) { input := p.input r := regexp.MustCompile(`(\w+) (\d+) (.*)`) matches := r.FindStringSubmatch(input) + if len(matches) < 4 { + fmt.Println("Could match command, id or subject") + return "", -1, input + } id, err := strconv.Atoi(matches[2]) if err != nil { fmt.Println("Invalid id.") - id = -1 + return "", -1, input } return matches[1], id, matches[3] -- cgit v1.3