-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patherrors.go
112 lines (92 loc) · 3.19 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
109
110
111
112
// Copyright 2017 Santhosh Kumar Tekuri. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xpath
import (
"errors"
"fmt"
"runtime"
)
// UnresolvedPrefixError is the error type returned by *Compiler.Compile function.
//
// It tells that no URI is bound for that prefix.
type UnresolvedPrefixError string
func (e UnresolvedPrefixError) Error() string {
return fmt.Sprintf("unresolved prefix: %s", string(e))
}
// UnresolvedVariableError is the error type returned by *XPath.Eval function.
//
// It tells that no variable is bound for that clarkName.
type UnresolvedVariableError string
func (e UnresolvedVariableError) Error() string {
return fmt.Sprintf("unresolved variable: %s", string(e))
}
// UnresolvedFunctionError is the error type returned by *Compiler.Compile function.
//
// It tells that no function is bound for that clarkName.
type UnresolvedFunctionError string
func (e UnresolvedFunctionError) Error() string {
return fmt.Sprintf("unresolved function: %s", string(e))
}
// SignatureError is the error type returned by *Compiler.Compile function.
//
// It tells that function registered for that clarkName has invalid signature.
// """
// the signature is valid only if:
// - variadic argument can appear only as last argument.
// - all mandatory arguments must precede optional and variadic arguments.
// """
type SignatureError string
func (e SignatureError) Error() string {
return fmt.Sprintf("function %s has invalid argument signature", string(e))
}
// ArgCountError is the error type returned by *Compiler.Compile function.
//
// It tells that function registered for that clarkName does not accept the
// number of args specified in xpath expression.
type ArgCountError string
func (e ArgCountError) Error() string {
return fmt.Sprintf("wrong number of args to function %s", string(e))
}
// InvalidValueError is the error type returned by *XPath.Eval function.
//
// It tells that function registered returned value other than
// []dom.Node, string, float64 or boolean
type InvalidValueError struct {
val interface{}
}
func (e InvalidValueError) Error() string {
return fmt.Sprintf("%T is not valid xpath data-type", e.val)
}
// VarMustBeNodeSet is the error type returned by *XPath.Eval function.
//
// It tells that variable or function that is expected to evaluate to
// []dom.Node results in value that is not []dom.Node.
type VarMustBeNodeSet string
func (e VarMustBeNodeSet) Error() string {
return fmt.Sprintf("variable %s must evaluate to node-set", string(e))
}
// ConversionError is the error type returned by *XPath.EvalNodeSet
//
// It tells that the value of type Src cannot be converted to value of type Target
type ConversionError struct {
// Src is DataType of source value
Src DataType
// Target is DataType the source value is requested to convert
Target DataType
}
func (e ConversionError) Error() string {
return fmt.Sprintf("%v cannot be converted to %v", e.Src, e.Target)
}
func panic2error(r interface{}, errRef *error) {
if r != nil {
if _, ok := r.(runtime.Error); ok {
panic(r)
}
if err, ok := r.(error); ok {
*errRef = err
} else {
*errRef = errors.New(fmt.Sprint(r))
}
}
}