-
Notifications
You must be signed in to change notification settings - Fork 2
/
error.go
102 lines (79 loc) · 2.06 KB
/
error.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
package pico
import (
"fmt"
"github.com/pkg/errors"
)
type GetBinaryVersionError struct {
msg string
}
type PerPageTimeoutError struct {
msg string
}
type PDFSyntaxError struct {
msg string
}
type WrongArgumentError struct {
msg string
}
type ConversionError struct {
pdf string
page int32
workerId int32
err error
}
func (e *ConversionError) Cause() error {
return e.err
}
func (e *ConversionError) Error() string {
worker, page := "", ""
if e.workerId >= 0 {
worker = fmt.Sprintf(" by worker#%02d", e.workerId)
}
if e.page >= 0 {
page = fmt.Sprintf(" at page %d", e.page)
}
return fmt.Sprintf("failed to convert %s%s%s: %s", e.pdf, worker, page, e.err)
}
var ErrProviderClosed = errors.New("provider is closed")
func NewPerPageTimeoutError(page string) *PerPageTimeoutError {
return &PerPageTimeoutError{
msg: fmt.Sprintf("processing page %s timeout", page),
}
}
func (e *PerPageTimeoutError) Error() string {
return e.msg
}
func newWrongArgumentError(detail string) *WrongArgumentError {
return &WrongArgumentError{
msg: fmt.Sprintf("wrong argument: %s", detail),
}
}
// Wrong page range given: the first page (21) can not be after the last page (14).
func newWrongPageRangeError(first, last int32) *WrongArgumentError {
return newWrongArgumentError(fmt.Sprintf("the first page (%d) can not be after the last page (%d)", first, last))
}
func (e *WrongArgumentError) Error() string {
return e.msg
}
func NewGetBinaryVersionError(binary string) *GetBinaryVersionError {
return &GetBinaryVersionError{
msg: fmt.Sprintf("failed to get version of %s binary", binary),
}
}
func (e *GetBinaryVersionError) Error() string {
return e.msg
}
func NewOldPDFSyntaxError(line, filename string, page int32) *PDFSyntaxError {
return &PDFSyntaxError{
msg: fmt.Sprintf("syntax error was thrown during rendering %s at page %d: %s",
filename, page, line),
}
}
func NewPDFSyntaxError(line string) *PDFSyntaxError {
return &PDFSyntaxError{
msg: fmt.Sprintf("poppler: %s", line),
}
}
func (e *PDFSyntaxError) Error() string {
return e.msg
}