diff --git a/pttodo/root.go b/pttodo/root.go index ff7baee..13946d5 100644 --- a/pttodo/root.go +++ b/pttodo/root.go @@ -2,6 +2,7 @@ package pttodo import ( "bytes" + "fmt" "os" yaml "gopkg.in/yaml.v2" @@ -44,7 +45,7 @@ func NewRootFromFile(p string) (Root, error) { if err := yaml.NewDecoder(f).Decode(&result); err != nil { todos, err2 := NewTodosFromFile(p) if err2 != nil { - return Root{}, err + return Root{}, fmt.Errorf("failed to parse yaml from %s: %w", p, err) } result.Todo = todos } diff --git a/pttodo/schedule.go b/pttodo/schedule.go index 207626d..ca3237c 100644 --- a/pttodo/schedule.go +++ b/pttodo/schedule.go @@ -2,6 +2,7 @@ package pttodo import ( "encoding/json" + "fmt" "math" "regexp" "strconv" @@ -17,7 +18,10 @@ func (schedule Schedule) MarshalJSON() ([]byte, error) { } func (schedule *Schedule) UnmarshalJSON(b []byte) error { - return json.Unmarshal(b, (*string)(schedule)) + if err := json.Unmarshal(b, (*string)(schedule)); err != nil { + return fmt.Errorf("failed to parse json from %q: %w", b, err) + } + return nil } func (schedule Schedule) Next(t time.Time) (time.Time, error) { diff --git a/pttodo/todo.go b/pttodo/todo.go index bbe4805..969627b 100644 --- a/pttodo/todo.go +++ b/pttodo/todo.go @@ -32,7 +32,7 @@ func NewTodosFromFile(p string) ([]Todo, error) { var result []Todo if err := yaml.NewDecoder(f).Decode(&result); err != nil { - return nil, err + return nil, fmt.Errorf("failed to parse yaml from %s: %w", p, err) } return result, nil diff --git a/pttodo/ts.go b/pttodo/ts.go index e6c0d21..dc9a788 100644 --- a/pttodo/ts.go +++ b/pttodo/ts.go @@ -3,6 +3,7 @@ package pttodo import ( "encoding/json" "errors" + "fmt" "time" yaml "gopkg.in/yaml.v2" @@ -33,7 +34,10 @@ func (ts TS) MarshalYAML() (interface{}, error) { } func (ts *TS) UnmarshalJSON(b []byte) error { - return yaml.Unmarshal(b, ts) + if err := yaml.Unmarshal(b, ts); err != nil { + return fmt.Errorf("faild to unmarshal TS from %q: %w", b, err) + } + return nil } func (ts *TS) UnmarshalYAML(unmarshaller func(interface{}) error) error {