-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
108 lines (83 loc) · 2.49 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package m3u8
import (
"fmt"
)
var (
ErrNoHeader = &Error{"missing header tag"}
ErrMixedTags = &Error{"playlist contains both master and media tags"}
ErrUnknownType = &Error{"failed to determine playlist type"}
ErrBadSyntax = &Error{"invalid syntax"}
ErrBadAttrName = &Error{"invalid attribute name"}
ErrBadAttrSyntax = &Error{"invalid attribute syntax"}
ErrBadEncryptionMethod = &Error{"invalid encryption method"}
ErrBadPlaylistType = &Error{"invalid playlist type"}
ErrNoRangeStart = &Error{"missing range start"}
ErrNotASegment = &Error{"not a segment"}
ErrUnexpectedMediaSegment = &Error{"found media segment after a " + endlistTag + " tag"}
ErrMissingURI = &Error{"missing uri"}
ErrUnexpectedURI = &Error{"unexpected uri"}
ErrBadVersionNumber = &Error{"invalid version number"}
)
type Error struct {
msg string
}
func (e *Error) Error() string {
return "m3u8: " + e.msg
}
type missingRequiredAttrError struct {
attrName string
}
func (e *missingRequiredAttrError) msg() string {
return `missing required attribute, "` + e.attrName + `",`
}
func (e *missingRequiredAttrError) Error() string {
return "m3u8: " + e.msg()
}
type invalidAttributeValueError struct {
attrName string
}
func (e *invalidAttributeValueError) msg() string {
return `invalid value for attribute, "` + e.attrName + `",`
}
func (e *invalidAttributeValueError) Error() string {
return "m3u8: " + e.msg()
}
type UnexpectedTagError split
func (e *UnexpectedTagError) Error() string {
return fmt.Sprintf(`m3u8: unexpected tag in "%s"`, (*split)(e).line())
}
type CompatibilityVersionError struct {
*split
version int
}
func (e *CompatibilityVersionError) Error() string {
return fmt.Sprintf(`m3u8: compatibility version number, %d, required on line %d (%s)`, e.version, e.num, e.line())
}
type InvalidSyntaxError struct {
*split
msg string
}
func (e *InvalidSyntaxError) Error() string {
msg := e.msg
if msg == "" {
msg = "invalid syntax"
}
return fmt.Sprintf(`m3u8: %s on line %d (%s)`, msg, e.num, e.line())
}
func ise(s *split, msg string) *InvalidSyntaxError {
return &InvalidSyntaxError{
split: s,
msg: msg,
}
}
func isew(s *split, err error) error {
switch err := err.(type) {
case *missingRequiredAttrError:
return ise(s, err.msg())
case *CompatibilityVersionError:
return &CompatibilityVersionError{s, err.version}
case *Error:
return ise(s, err.msg)
}
return err
}