master
Bel LaPointe 2025-01-14 21:19:39 -07:00
parent 44488aec2d
commit 29bc6a06b4
4 changed files with 13 additions and 4 deletions

View File

@ -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
}

View File

@ -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) {

View File

@ -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

View File

@ -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 {