-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patherror.go
97 lines (82 loc) · 2.71 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
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package main
// #include "uplink_definitions.h"
import "C"
import (
"context"
"errors"
"fmt"
"io"
"unsafe"
"github.com/zeebo/errs"
"storj.io/uplink"
"storj.io/uplink/edge"
)
var (
// ErrInvalidHandle is used when the handle passed as an argument is invalid.
ErrInvalidHandle = errs.Class("invalid handle")
// ErrNull is returned when an argument is NULL, however it should not be.
ErrNull = errs.Class("NULL")
// ErrInvalidArg is returned when the argument is not valid.
ErrInvalidArg = errs.Class("invalid argument")
)
func mallocError(err error) *C.UplinkError {
if err == nil {
return nil
}
cerror := (*C.UplinkError)(calloc(1, C.sizeof_UplinkError))
switch {
case errors.Is(err, io.EOF):
cerror.code = C.EOF
return cerror
case errors.Is(err, context.Canceled):
cerror.code = C.UPLINK_ERROR_CANCELED
case ErrInvalidHandle.Has(err):
cerror.code = C.UPLINK_ERROR_INVALID_HANDLE
case errors.Is(err, uplink.ErrTooManyRequests):
cerror.code = C.UPLINK_ERROR_TOO_MANY_REQUESTS
case errors.Is(err, uplink.ErrBandwidthLimitExceeded):
cerror.code = C.UPLINK_ERROR_BANDWIDTH_LIMIT_EXCEEDED
case errors.Is(err, uplink.ErrStorageLimitExceeded):
cerror.code = C.UPLINK_ERROR_STORAGE_LIMIT_EXCEEDED
case errors.Is(err, uplink.ErrSegmentsLimitExceeded):
cerror.code = C.UPLINK_ERROR_SEGMENTS_LIMIT_EXCEEDED
case errors.Is(err, uplink.ErrPermissionDenied):
cerror.code = C.UPLINK_ERROR_PERMISSION_DENIED
case errors.Is(err, uplink.ErrBucketNameInvalid):
cerror.code = C.UPLINK_ERROR_BUCKET_NAME_INVALID
case errors.Is(err, uplink.ErrBucketAlreadyExists):
cerror.code = C.UPLINK_ERROR_BUCKET_ALREADY_EXISTS
case errors.Is(err, uplink.ErrBucketNotEmpty):
cerror.code = C.UPLINK_ERROR_BUCKET_NOT_EMPTY
case errors.Is(err, uplink.ErrBucketNotFound):
cerror.code = C.UPLINK_ERROR_BUCKET_NOT_FOUND
case errors.Is(err, uplink.ErrObjectKeyInvalid):
cerror.code = C.UPLINK_ERROR_OBJECT_KEY_INVALID
case errors.Is(err, uplink.ErrObjectNotFound):
cerror.code = C.UPLINK_ERROR_OBJECT_NOT_FOUND
case errors.Is(err, uplink.ErrUploadDone):
cerror.code = C.UPLINK_ERROR_UPLOAD_DONE
case errors.Is(err, edge.ErrAuthDialFailed):
cerror.code = C.EDGE_ERROR_AUTH_DIAL_FAILED
case errors.Is(err, edge.ErrRegisterAccessFailed):
cerror.code = C.EDGE_ERROR_REGISTER_ACCESS_FAILED
default:
cerror.code = C.UPLINK_ERROR_INTERNAL
}
cerror.message = C.CString(fmt.Sprintf("%+v", err))
return cerror
}
// uplink_free_error frees error data.
//
//export uplink_free_error
func uplink_free_error(err *C.UplinkError) {
if err == nil {
return
}
defer C.free(unsafe.Pointer(err))
if err.message != nil {
C.free(unsafe.Pointer(err.message))
}
}