@@ -20,6 +20,7 @@ import (
20
20
"bytes"
21
21
"fmt"
22
22
"runtime"
23
+ "strings"
23
24
24
25
"github.com/hyperledger/fabric/common/flogging"
25
26
logging "github.com/op/go-logging"
@@ -28,12 +29,6 @@ import (
28
29
// MaxCallStackLength is the maximum length of the stored call stack
29
30
const MaxCallStackLength = 30
30
31
31
- // ComponentCode shows the originating component/module
32
- type ComponentCode string
33
-
34
- // ReasonCode for low level error description
35
- type ReasonCode string
36
-
37
32
var errorLogger = logging .MustGetLogger ("error" )
38
33
39
34
// CallStackError is a general interface for
@@ -42,8 +37,8 @@ type CallStackError interface {
42
37
error
43
38
GetStack () string
44
39
GetErrorCode () string
45
- GetComponentCode () ComponentCode
46
- GetReasonCode () ReasonCode
40
+ GetComponentCode () string
41
+ GetReasonCode () string
47
42
Message () string
48
43
}
49
44
@@ -56,8 +51,8 @@ type callstack []uintptr
56
51
// create something more useful
57
52
type hlError struct {
58
53
stack callstack
59
- componentcode ComponentCode
60
- reasoncode ReasonCode
54
+ componentcode string
55
+ reasoncode string
61
56
message string
62
57
args []interface {}
63
58
stackGetter func (callstack ) string
@@ -72,8 +67,8 @@ func newHLError(debug bool) *hlError {
72
67
}
73
68
74
69
func setupHLError (e * hlError , debug bool ) {
75
- e .componentcode = "Utility "
76
- e .reasoncode = "UnknownError "
70
+ e .componentcode = "UTILITY "
71
+ e .reasoncode = "UNKNOWNERROR "
77
72
e .message = "An unknown error has occurred."
78
73
if ! debug {
79
74
e .stackGetter = noopGetStack
@@ -97,18 +92,18 @@ func (h *hlError) GetStack() string {
97
92
}
98
93
99
94
// GetComponentCode returns the component name
100
- func (h * hlError ) GetComponentCode () ComponentCode {
95
+ func (h * hlError ) GetComponentCode () string {
101
96
return h .componentcode
102
97
}
103
98
104
99
// GetReasonCode returns the reason code - i.e. why the error occurred
105
- func (h * hlError ) GetReasonCode () ReasonCode {
100
+ func (h * hlError ) GetReasonCode () string {
106
101
return h .reasoncode
107
102
}
108
103
109
104
// GetErrorCode returns a formatted error code string
110
105
func (h * hlError ) GetErrorCode () string {
111
- return fmt .Sprintf ("%s- %s" , h .componentcode , h .reasoncode )
106
+ return fmt .Sprintf ("%s_ %s" , h .componentcode , h .reasoncode )
112
107
}
113
108
114
109
// Message returns the corresponding error message for this error in default
@@ -119,7 +114,7 @@ func (h *hlError) Message() string {
119
114
// "peer logging setlevel error <log-level>"
120
115
errorLogLevelString , _ := flogging .GetModuleLevel ("error" )
121
116
122
- message := fmt .Sprintf (h .message , h .args ... )
117
+ message := h . GetErrorCode () + " - " + fmt .Sprintf (h .message , h .args ... )
123
118
if errorLogLevelString == logging .DEBUG .String () {
124
119
message = appendCallStack (message , h .GetStack ())
125
120
}
@@ -135,23 +130,23 @@ func appendCallStack(message string, callstack string) string {
135
130
136
131
// Error creates a CallStackError using a specific Component Code and
137
132
// Reason Code (no callstack is recorded)
138
- func Error (componentcode ComponentCode , reasoncode ReasonCode , message string , args ... interface {}) CallStackError {
133
+ func Error (componentcode string , reasoncode string , message string , args ... interface {}) CallStackError {
139
134
return newCustomError (componentcode , reasoncode , message , false , args ... )
140
135
}
141
136
142
137
// ErrorWithCallstack creates a CallStackError using a specific Component Code and
143
138
// Reason Code and fills its callstack
144
- func ErrorWithCallstack (componentcode ComponentCode , reasoncode ReasonCode , message string , args ... interface {}) CallStackError {
139
+ func ErrorWithCallstack (componentcode string , reasoncode string , message string , args ... interface {}) CallStackError {
145
140
return newCustomError (componentcode , reasoncode , message , true , args ... )
146
141
}
147
142
148
- func newCustomError (componentcode ComponentCode , reasoncode ReasonCode , message string , generateStack bool , args ... interface {}) CallStackError {
143
+ func newCustomError (componentcode string , reasoncode string , message string , generateStack bool , args ... interface {}) CallStackError {
149
144
e := & hlError {}
150
145
setupHLError (e , generateStack )
151
- e .componentcode = componentcode
152
- e .reasoncode = reasoncode
153
- e .args = args
146
+ e .componentcode = strings .ToUpper (componentcode )
147
+ e .reasoncode = strings .ToUpper (reasoncode )
154
148
e .message = message
149
+ e .args = args
155
150
return e
156
151
}
157
152
0 commit comments