forked from ami-GS/go-cdds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
96 lines (83 loc) · 1.78 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
package gocdds
/*
#cgo CFLAGS: -I/usr/include
#cgo LDFLAGS: -lddsc
#include "ddsc/dds.h"
#include "ddsc/dds.h"
*/
import (
"C"
"math"
)
type CddsErrorType uint16
const DDS_XRETCODE_BASE = -50
const (
Ok CddsErrorType = iota
Error
Unsupported
BadParameter
PreconditionNotMet
OutOfResource
NotEnabled
ImmutablePolicy
AlreadyDeleted
TimeOut
NoData
IllegalOperation
NotAllowedBySecurity
)
var retcodes = []string{
"Success",
"Non specific error",
"Feature unsupported",
"Bad parameter value",
"Precondition for operation not met",
"Out of resources",
"Configurable feature is not enabled",
"Attempt is made to modify an immutable policy",
"Policy is used with inconsistent values",
"Attempt is made to delete something more than once",
"Timeout",
"Expected data is not provided",
"Function is called when it should not be",
"Credentials are not enough to use the function",
}
var xretcodes = []string{
"Unknown return code",
"Operation in progress",
"Try again",
"Interrupted",
"Not allowed",
"Host not found",
"Network not available",
"Connection not available",
"No space left",
"Result too large",
"Not found",
}
func (e CddsErrorType) Error() string {
return retcodes[int(e)]
}
func (e CddsErrorType) XError() string {
return xretcodes[int(e)]
}
func CddsStrretcode(rc uint32) string {
nretcodes := uint32(len(retcodes))
nxretcodes := uint32(len(xretcodes))
if DDS_XRETCODE_BASE >= 0 {
panic("DDS_XRETCODE_BASE must be negative")
}
if uint32(rc) == ^uint32(math.MaxInt32) {
return xretcodes[0]
}
if rc < 0 {
rc = -rc
}
if rc >= 0 && rc < nretcodes {
return retcodes[rc]
} else if rc >= uint32(-DDS_XRETCODE_BASE) && rc < uint32(-DDS_XRETCODE_BASE)+nxretcodes {
return xretcodes[rc-uint32(-DDS_XRETCODE_BASE)]
} else {
return xretcodes[0]
}
}