/
errors.go
63 lines (48 loc) · 1.81 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
package webcrypto
// ErrorName is a type alias for the name of a WebCryptoError.
//
// Note that it is a type alias, and not a binding, so that it is
// not interpreted as an object by goja.
type ErrorName = string
const (
// DataError represents the DataError error.
DataError = "DataError"
// ImplementationError represents the ImplementationError error.
// It is thrown when the error is likely a bug in our implementation.
ImplementationError = "ImplementationError"
// InvalidAccessError represents the InvalidAccessError error.
InvalidAccessError = "InvalidAccessError"
// NotSupportedError represents the NotSupportedError error.
NotSupportedError ErrorName = "NotSupportedError"
// OperationError represents the OperationError error.
OperationError = "OperationError"
// SyntaxError represents the SyntaxError error.
SyntaxError = "SyntaxError"
// TypeMismatchError represents the TypeMismatchError error.
TypeMismatchError = "TypeMismatchError"
// TypeError represents the TypeError error.
TypeError = "TypeError"
// QuotaExceededError is the error thrown if the byteLength of a typedArray
// exceeds 65,536.
QuotaExceededError = "QuotaExceededError"
)
// Error represents a custom error emitted by the
// Web Crypto API.
type Error struct {
// Name contains one of the strings associated with an error name.
Name string `js:"name"`
// Message represents message or description associated with the given error name.
Message string `js:"message"`
}
// Error implements the `error` interface, so WebCryptoError are normal Go errors.
func (e *Error) Error() string {
return e.Name + ": " + e.Message
}
// NewError returns a new WebCryptoError with the given name and message.
func NewError(name, message string) *Error {
return &Error{
Name: name,
Message: message,
}
}
var _ error = (*Error)(nil)