-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.go
More file actions
240 lines (206 loc) · 8.44 KB
/
Copy patherrors.go
File metadata and controls
240 lines (206 loc) · 8.44 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// SPDX-License-Identifier: Apache-2.0
package epub
import (
"errors"
"fmt"
)
var (
// ErrInvalidMimeType is returned when the mimetype file is missing or has an invalid value.
ErrInvalidMimeType = errors.New("mimetype must be 'application/epub+zip' and uncompressed")
// ErrMimeTypeNotFirst is returned when mimetype is not the first ZIP entry.
ErrMimeTypeNotFirst = errors.New("mimetype must be the first ZIP entry")
// ErrContainerNotFound is returned when the container.xml file is missing.
ErrContainerNotFound = errors.New("META-INF/container.xml not found")
// ErrOPFNotFound is returned when OPF rootfile is missing.
ErrOPFNotFound = errors.New("OPF rootfile not found")
// ErrManifestMissing is returned when OPF manifest is not present.
ErrManifestMissing = errors.New("OPF manifest is missing")
// ErrSpineMissing is returned when OPF spine is not present.
ErrSpineMissing = errors.New("OPF spine is missing")
// ErrInvalidViewport is returned when viewport meta cannot be parsed.
ErrInvalidViewport = errors.New("invalid viewport meta")
// ErrAssetNotFound is returned when an asset cannot be resolved from the current document.
ErrAssetNotFound = errors.New("asset not found")
// ErrNilAsset is returned when asset receiver is nil.
ErrNilAsset = errors.New("asset is nil")
// ErrNilAssetOpen is returned when asset stream function is nil.
ErrNilAssetOpen = errors.New("asset Open function is nil")
// ErrNilDocument is returned when document receiver is nil.
ErrNilDocument = errors.New("document is nil")
// ErrNilPage is returned when page argument is nil.
ErrNilPage = errors.New("page is nil")
// ErrEmptyAssetID is returned when page asset id is empty.
ErrEmptyAssetID = errors.New("asset id is empty")
// ErrInvalidSpread is returned when page spread is unsupported.
ErrInvalidSpread = errors.New("spread must be one of left, right, center, none")
// ErrEmptyAssetPath is returned when asset href/path is empty.
ErrEmptyAssetPath = errors.New("asset href is empty")
// ErrDuplicateAssetPath is returned when the same href/path is already registered.
ErrDuplicateAssetPath = errors.New("asset href is already registered")
// ErrDuplicateAssetID is returned when the same asset id is already registered.
ErrDuplicateAssetID = errors.New("asset id is already registered")
// ErrEmptyMimeType is returned when asset media type is empty.
ErrEmptyMimeType = errors.New("asset mime type is empty")
// ErrNilReaderAt is returned when io.ReaderAt source is nil.
ErrNilReaderAt = errors.New("asset readerAt is nil")
// ErrInvalidAssetSize is returned when asset size is negative.
ErrInvalidAssetSize = errors.New("asset size must be >= 0")
// ErrCannotInferAssetPath is returned when href is empty and mime type cannot be mapped to an extension.
ErrCannotInferAssetPath = errors.New("cannot infer asset href from mime type")
// ErrCannotInferAssetSize is returned when a ReaderAt length cannot be inferred.
ErrCannotInferAssetSize = errors.New("cannot infer asset size from readerAt")
errInvalidImageNaming = errors.New("image path must follow item/image/p-000.(jpg|png) format")
errInvalidDirectoryLayout = errors.New("asset path must be under item/xhtml, item/image, or item/style")
)
// SpineUnknownIDRefError is returned when a spine itemref points to an unknown manifest ID.
type SpineUnknownIDRefError struct {
IDRef string
}
func (e *SpineUnknownIDRefError) Error() string {
if e == nil || e.IDRef == "" {
return "spine itemref references unknown manifest id"
}
return fmt.Sprintf("spine itemref references unknown manifest id %q", e.IDRef)
}
func (e *SpineUnknownIDRefError) Is(target error) bool {
_, ok := target.(*SpineUnknownIDRefError)
return ok
}
// ManifestPhysicalMissingError is returned when a manifest item href does not exist in the ZIP.
type ManifestPhysicalMissingError struct {
Href string
}
func (e *ManifestPhysicalMissingError) Error() string {
if e == nil || e.Href == "" {
return "manifest item href does not exist in ZIP"
}
return fmt.Sprintf("manifest item href %q does not exist in ZIP", e.Href)
}
func (e *ManifestPhysicalMissingError) Is(target error) bool {
_, ok := target.(*ManifestPhysicalMissingError)
return ok
}
// MaxAssetCountExceededError is returned when ZIP entry count exceeds configured limit.
type MaxAssetCountExceededError struct {
Limit int
Actual int
}
func (e *MaxAssetCountExceededError) Error() string {
if e == nil {
return "zip entry count exceeds configured limit"
}
return fmt.Sprintf("zip entry count exceeds configured limit: actual=%d limit=%d", e.Actual, e.Limit)
}
func (e *MaxAssetCountExceededError) Is(target error) bool {
_, ok := target.(*MaxAssetCountExceededError)
return ok
}
// MaxTotalUncompressedSizeExceededError is returned when total ZIP uncompressed size exceeds configured limit.
type MaxTotalUncompressedSizeExceededError struct {
Limit int64
Actual uint64
}
func (e *MaxTotalUncompressedSizeExceededError) Error() string {
if e == nil {
return "total uncompressed size exceeds configured limit"
}
return fmt.Sprintf("total uncompressed size exceeds configured limit: actual=%d limit=%d", e.Actual, e.Limit)
}
func (e *MaxTotalUncompressedSizeExceededError) Is(target error) bool {
_, ok := target.(*MaxTotalUncompressedSizeExceededError)
return ok
}
// MaxIndividualAssetSizeExceededError is returned when a ZIP entry uncompressed size exceeds configured limit.
type MaxIndividualAssetSizeExceededError struct {
Name string
Limit int64
Actual uint64
}
func (e *MaxIndividualAssetSizeExceededError) Error() string {
if e == nil {
return "individual uncompressed size exceeds configured limit"
}
if e.Name == "" {
return fmt.Sprintf("individual uncompressed size exceeds configured limit: actual=%d limit=%d", e.Actual, e.Limit)
}
return fmt.Sprintf("individual uncompressed size exceeds configured limit for %q: actual=%d limit=%d", e.Name, e.Actual, e.Limit)
}
func (e *MaxIndividualAssetSizeExceededError) Is(target error) bool {
_, ok := target.(*MaxIndividualAssetSizeExceededError)
return ok
}
// DecodeError represents an error that occurred during the decoding of an EPUB file, including the path where the error occurred and the underlying error.
type DecodeError struct {
Path string
Rule string
Err error
}
func (e *DecodeError) Error() string {
if e.Rule != "" {
return fmt.Sprintf("epub decode error at [%s] (%s): %v", e.Path, e.Rule, e.Err)
}
return fmt.Sprintf("epub decode error at [%s]: %v", e.Path, e.Err)
}
func (e *DecodeError) Unwrap() error { return e.Err }
// ImagePixelCountExceededError is returned when image pixel count exceeds the limit.
type ImagePixelCountExceededError struct {
Href string
Limit int64
Actual int64
}
func (e *ImagePixelCountExceededError) Error() string {
if e == nil || e.Href == "" {
return "image pixel count exceeds limit"
}
return fmt.Sprintf("image %q pixel count exceeds limit: %d > %d", e.Href, e.Actual, e.Limit)
}
func (e *ImagePixelCountExceededError) Is(target error) bool {
_, ok := target.(*ImagePixelCountExceededError)
return ok
}
// ImageFileSizeTooLargeError is returned when image file size exceeds the limit.
type ImageFileSizeTooLargeError struct {
Href string
Limit int64
Actual int64
}
func (e *ImageFileSizeTooLargeError) Error() string {
if e == nil || e.Href == "" {
return "image file size exceeds limit"
}
return fmt.Sprintf("image %q file size exceeds limit: %d > %d bytes", e.Href, e.Actual, e.Limit)
}
func (e *ImageFileSizeTooLargeError) Is(target error) bool {
_, ok := target.(*ImageFileSizeTooLargeError)
return ok
}
// ProgressiveJPEGNotAllowedError is returned when a progressive JPEG is detected.
type ProgressiveJPEGNotAllowedError struct {
Href string
}
func (e *ProgressiveJPEGNotAllowedError) Error() string {
if e == nil || e.Href == "" {
return "progressive JPEG is not allowed"
}
return fmt.Sprintf("image %q: progressive JPEG is not allowed", e.Href)
}
func (e *ProgressiveJPEGNotAllowedError) Is(target error) bool {
_, ok := target.(*ProgressiveJPEGNotAllowedError)
return ok
}
// InvalidColorSpaceError is returned when image has invalid color space.
type InvalidColorSpaceError struct {
Href string
Expected string
Actual string
}
func (e *InvalidColorSpaceError) Error() string {
if e == nil || e.Href == "" {
return "invalid color space"
}
return fmt.Sprintf("image %q has invalid color space: expected %s, got %s", e.Href, e.Expected, e.Actual)
}
func (e *InvalidColorSpaceError) Is(target error) bool {
_, ok := target.(*InvalidColorSpaceError)
return ok
}