Skip to content

Commit

Permalink
Declare errors to make easier for callers to detect
Browse files Browse the repository at this point in the history
  • Loading branch information
eric committed Nov 10, 2020
1 parent 2ce07e6 commit f05e61f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import (
"time"
)

// The #EXTM3U directive was not found
var ErrExtM3uAbsent = fmt.Errorf("#EXTM3U was not found")

// The playlist type could not be detected
var ErrUnknownPlaylistType = fmt.Errorf("Can't detect playlist type")

var reKeyValue = regexp.MustCompile(`([a-zA-Z0-9_-]+)=("[^"]+"|[^",]+)`)

// TimeParse allows globally apply and/or override Time Parser function.
Expand Down Expand Up @@ -79,7 +85,7 @@ func (p *MasterPlaylist) decode(buf *bytes.Buffer, strict bool) error {
}
}
if strict && !state.m3u {
return errors.New("#EXTM3U absent")
return ErrExtM3uAbsent
}
return nil
}
Expand Down Expand Up @@ -139,7 +145,7 @@ func (p *MediaPlaylist) decode(buf *bytes.Buffer, strict bool) error {
p.WV = wv
}
if strict && !state.m3u {
return errors.New("#EXTM3U absent")
return ErrExtM3uAbsent
}
return nil
}
Expand Down Expand Up @@ -235,7 +241,7 @@ func decode(buf *bytes.Buffer, strict bool, customDecoders []CustomDecoder) (Pla
}

if strict && !state.m3u {
return nil, listType, errors.New("#EXTM3U absent")
return nil, listType, ErrExtM3uAbsent
}

switch state.listType {
Expand All @@ -248,7 +254,7 @@ func decode(buf *bytes.Buffer, strict bool, customDecoders []CustomDecoder) (Pla
}
return media, MEDIA, nil
}
return nil, state.listType, errors.New("Can't detect playlist type")
return nil, state.listType, ErrUnknownPlaylistType
}

// DecodeAttributeList turns an attribute list into a key, value map. You should trim
Expand Down
2 changes: 1 addition & 1 deletion writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

// ErrPlaylistFull declares the playlist error.
var ErrPlaylistFull = errors.New("playlist is full")
var ErrPlaylistFull = fmt.Errorf("playlist is full")

// Set version of the playlist accordingly with section 7
func version(ver *uint8, newver uint8) {
Expand Down

0 comments on commit f05e61f

Please sign in to comment.