-
Notifications
You must be signed in to change notification settings - Fork 178
/
errors.go
65 lines (51 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
64
65
package execution_data
import (
"errors"
"fmt"
"github.com/ipfs/go-cid"
)
// MalformedDataError is returned when malformed data is found at some level of the requested
// blob tree. It likely indicates that the tree was generated incorrectly, and hence the request
// should not be retried.
type MalformedDataError struct {
err error
}
func NewMalformedDataError(err error) *MalformedDataError {
return &MalformedDataError{err: err}
}
func (e *MalformedDataError) Error() string {
return fmt.Sprintf("malformed data: %v", e.err)
}
func (e *MalformedDataError) Unwrap() error { return e.err }
// IsMalformedDataError returns whether an error is MalformedDataError
func IsMalformedDataError(err error) bool {
var malformedDataErr *MalformedDataError
return errors.As(err, &malformedDataErr)
}
// BlobNotFoundError is returned when a blob could not be found.
type BlobNotFoundError struct {
cid cid.Cid
}
func NewBlobNotFoundError(cid cid.Cid) *BlobNotFoundError {
return &BlobNotFoundError{cid: cid}
}
func (e *BlobNotFoundError) Error() string {
return fmt.Sprintf("blob %v not found", e.cid.String())
}
// IsBlobNotFoundError returns whether an error is BlobNotFoundError
func IsBlobNotFoundError(err error) bool {
var blobNotFoundError *BlobNotFoundError
return errors.As(err, &blobNotFoundError)
}
// BlobSizeLimitExceededError is returned when a blob exceeds the maximum size allowed.
type BlobSizeLimitExceededError struct {
cid cid.Cid
}
func (e *BlobSizeLimitExceededError) Error() string {
return fmt.Sprintf("blob %v exceeds maximum blob size", e.cid.String())
}
// IsBlobSizeLimitExceededError returns whether an error is BlobSizeLimitExceededError
func IsBlobSizeLimitExceededError(err error) bool {
var blobSizeLimitExceededError *BlobSizeLimitExceededError
return errors.As(err, &blobSizeLimitExceededError)
}