@@ -39,8 +39,9 @@ const (
39
39
40
40
// Result codes
41
41
const (
42
- // Placeholder
42
+ // Placeholders
43
43
UnknownError ReasonCode = iota
44
+ ErrorWithArg ReasonCode = 1
44
45
)
45
46
46
47
// CallStackError is a general interface for
@@ -51,6 +52,8 @@ type CallStackError interface {
51
52
GetErrorCode () string
52
53
GetComponentCode () ComponentCode
53
54
GetReasonCode () ReasonCode
55
+ Message () string
56
+ MessageIn (string ) string
54
57
}
55
58
56
59
type errormap map [string ]map [string ]map [string ]string
@@ -81,6 +84,7 @@ type hlError struct {
81
84
stack callstack
82
85
componentcode ComponentCode
83
86
reasoncode ReasonCode
87
+ args []interface {}
84
88
stackGetter func (callstack ) string
85
89
}
86
90
@@ -108,7 +112,7 @@ func setupHLError(e *hlError, debug bool) {
108
112
109
113
// Error comes from the error interface
110
114
func (h * hlError ) Error () string {
111
- return h .componentcode . Message (h . reasoncode )
115
+ return h .Message ()
112
116
}
113
117
114
118
// GetStack returns the call stack as a string
@@ -131,33 +135,37 @@ func (h *hlError) GetErrorCode() string {
131
135
return fmt .Sprintf ("%d-%d" , h .componentcode , h .reasoncode )
132
136
}
133
137
134
- // Message returns the corresponding error message for this code in default language
135
- func (c ComponentCode ) Message (reasoncode ReasonCode ) string {
136
- return emap [fmt .Sprintf ("%d" , c )][fmt .Sprintf ("%d" , reasoncode )][language ]
138
+ // Message returns the corresponding error message for this error in default
139
+ // language.
140
+ // TODO - figure out the best way to read in system language instead of using
141
+ // hard-coded default language
142
+ func (h * hlError ) Message () string {
143
+ return fmt .Sprintf (emap [fmt .Sprintf ("%d" , h .componentcode )][fmt .Sprintf ("%d" , h .reasoncode )][language ], h .args ... )
137
144
}
138
145
139
- // MessageIn returns the corresponding error message for this code in 'language'
140
- func (c ComponentCode ) MessageIn (reasoncode ReasonCode , language string ) string {
141
- return emap [fmt .Sprintf ("%d" , c )][fmt .Sprintf ("%d" , reasoncode )][language ]
146
+ // MessageIn returns the corresponding error message for this error in 'language'
147
+ func (h * hlError ) MessageIn (language string ) string {
148
+ return fmt . Sprintf ( emap [fmt .Sprintf ("%d" , h . componentcode )][fmt .Sprintf ("%d" , h . reasoncode )][language ], h . args ... )
142
149
}
143
150
144
151
// Error creates a CallStackError using a specific Component Code and
145
152
// Reason Code (no callstack is recorded)
146
- func Error (componentcode ComponentCode , reasoncode ReasonCode ) CallStackError {
147
- return newCustomError (componentcode , reasoncode , false )
153
+ func Error (componentcode ComponentCode , reasoncode ReasonCode , args ... interface {} ) CallStackError {
154
+ return newCustomError (componentcode , reasoncode , false , args ... )
148
155
}
149
156
150
157
// ErrorWithCallstack creates a CallStackError using a specific Component Code and
151
158
// Reason Code and fills its callstack
152
- func ErrorWithCallstack (componentcode ComponentCode , reasoncode ReasonCode ) CallStackError {
153
- return newCustomError (componentcode , reasoncode , true )
159
+ func ErrorWithCallstack (componentcode ComponentCode , reasoncode ReasonCode , args ... interface {} ) CallStackError {
160
+ return newCustomError (componentcode , reasoncode , true , args ... )
154
161
}
155
162
156
- func newCustomError (componentcode ComponentCode , reasoncode ReasonCode , generateStack bool ) CallStackError {
163
+ func newCustomError (componentcode ComponentCode , reasoncode ReasonCode , generateStack bool , args ... interface {} ) CallStackError {
157
164
e := & hlError {}
158
165
setupHLError (e , generateStack )
159
166
e .componentcode = componentcode
160
167
e .reasoncode = reasoncode
168
+ e .args = args
161
169
return e
162
170
}
163
171
0 commit comments