Skip to content

Commit

Permalink
add file path to ical decoding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Oct 5, 2021
1 parent 711dfb2 commit 91a62ed
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
15 changes: 14 additions & 1 deletion vdir/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ type Item struct {
// Tag represents a hashtag label in todo summary
type Tag string

// DecodeError represents and error occured during ical decoding
type DecodeError struct {
Path string
Err error
}

func (d *DecodeError) Error() string {
return fmt.Sprintf("%s\npath: %s", d.Err, d.Path)
}

// String returns a lowercased tag string
func (t Tag) String() string {
return strings.ToLower(string(t))
Expand All @@ -80,7 +90,10 @@ func (i *Item) Init(path string) error {
if err == io.EOF {
break
} else if err != nil {
return err
return &DecodeError{
i.Path,
err,
}
}

// filter only items that contain vtodo
Expand Down
14 changes: 14 additions & 0 deletions vdir/testdata/vdir/corrupted/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:example.com
BEGIN:VTODO
UID:[email protected]
DTSTAMP:20070514T103211Z
DTSTART:20070514T110000Z
DUE:20070709T130000Z
COMPLETED20070707T100000Z
SUMMARY: New Submit Revised Internet-Draft
PRIORITY:1
STATUS:NEEDS-ACTION
END:VTODO
END:VCALENDAR
19 changes: 7 additions & 12 deletions vdir/vdir_test.go.bak → vdir/vdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,21 @@ import (
"github.com/emersion/go-ical"
)

var (
cwd, _ = os.Getwd()
// testVdirPath = path.Join(cwd, "test_data")
testVdirPath = path.Join("/home/kkga/.local/share/calendars/")
)

func TestCollections(t *testing.T) {
func TestInit(t *testing.T) {
cwd, _ := os.Getwd()
vdpath := path.Join(cwd, "testdata/vdir/corrupted/")
var tests = []struct {
path string
}{
{testVdirPath},
{vdpath},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
vd := new(Vdir)
err := vd.Init(tt.path)
if err != nil {
vd := Vdir{}
if err := vd.Init(tt.path); err != nil {
t.Fatal(err)
}
for col, items := range *vd {
for col, items := range vd {
for _, item := range items {
summary := item.Ical.Children[0].Props.Get(ical.PropSummary)
fmt.Printf("%s: %+s\n", col, summary)
Expand Down

0 comments on commit 91a62ed

Please sign in to comment.