From bafbc3578cf9662317e2914fc58450f769a49016 Mon Sep 17 00:00:00 2001 From: Nick Griffey Date: Thu, 22 Feb 2024 23:36:57 -0600 Subject: [PATCH] return errors --- main.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index e2aecd7..c11fd2a 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,6 @@ func formula(p float64) int64 { } func (db *TimelineDB) closestEvent(t int64) (EventsRow, error) { - var event EventsRow query := ` select description, timestamp, yearknown, monthknown, dayknown, hourknown, minuteknown, secondknown from events @@ -43,6 +42,7 @@ func (db *TimelineDB) closestEvent(t int64) (EventsRow, error) { limit 1 ` + var event EventsRow stmt, err := db.Prepare(query) if err != nil { return event, err @@ -53,20 +53,20 @@ func (db *TimelineDB) closestEvent(t int64) (EventsRow, error) { return event, err } -func (event *EventsRow) Output() (int64, string, string) { +func (event *EventsRow) Output() (int64, string, string, error) { timestamp, err := event.timestamp.Value() if err != nil { - log.Fatal(err) + return 0, "", "", err } desc, err := event.description.Value() if err != nil { - log.Fatal(err) + return 0, "", "", err } yearknown, err := event.yearknown.Value() if err != nil { - log.Fatal(err) + return 0, "", "", err } var ago string @@ -78,7 +78,7 @@ func (event *EventsRow) Output() (int64, string, string) { ago = date.String() } - return timestamp.(int64), ago, desc.(string) + return timestamp.(int64), ago, desc.(string), nil } func main() { @@ -104,6 +104,10 @@ func main() { log.Fatal(err) } - timestamp, date, desc := event.Output() + timestamp, date, desc, err := event.Output() + if err != nil { + log.Fatal(err) + } + fmt.Printf("%v\t%v\t%v\n", timestamp, date, desc) }