@@ -45,6 +45,7 @@ func TestError_HTTPStatusCode(t *testing.T) {
45
45
httpStatusCode ,
46
46
"Test Msg" ,
47
47
"SOME_ERROR" ,
48
+ "some_category" ,
48
49
).
49
50
WithErrorInfo ("fake" , map [string ]string {"fake" : "test" }).
50
51
Build ()
@@ -60,6 +61,7 @@ func TestError_GrpcStatusCode(t *testing.T) {
60
61
http .StatusTeapot ,
61
62
"Test Msg" ,
62
63
"SOME_ERROR" ,
64
+ "some_category" ,
63
65
).
64
66
WithErrorInfo ("fake" , map [string ]string {"fake" : "test" }).
65
67
Build ()
@@ -125,6 +127,7 @@ func TestError_Error(t *testing.T) {
125
127
http .StatusTeapot ,
126
128
"Msg" ,
127
129
"SOME_ERROR" ,
130
+ "some_category" ,
128
131
).WithErrorInfo ("fake" , map [string ]string {"fake" : "test" }),
129
132
fields : fields {
130
133
message : "Msg" ,
@@ -139,6 +142,7 @@ func TestError_Error(t *testing.T) {
139
142
http .StatusTeapot ,
140
143
"Msg" ,
141
144
"SOME_ERROR" ,
145
+ "some_category" ,
142
146
).WithErrorInfo ("fake" , map [string ]string {"fake" : "test" }),
143
147
fields : fields {
144
148
message : "Msg" ,
@@ -152,6 +156,7 @@ func TestError_Error(t *testing.T) {
152
156
http .StatusTeapot ,
153
157
"Msg" ,
154
158
"SOME_ERROR" ,
159
+ "some_category" ,
155
160
).WithErrorInfo ("fake" , map [string ]string {"fake" : "test" }),
156
161
fields : fields {
157
162
grpcCode : grpcCodes .Canceled ,
@@ -186,6 +191,7 @@ func TestErrorBuilder_WithErrorInfo(t *testing.T) {
186
191
httpCode : http .StatusTeapot ,
187
192
message : "fake_message" ,
188
193
tag : "DAPR_FAKE_TAG" ,
194
+ category : "some_category" ,
189
195
details : []proto.Message {
190
196
details ,
191
197
},
@@ -196,6 +202,7 @@ func TestErrorBuilder_WithErrorInfo(t *testing.T) {
196
202
http .StatusTeapot ,
197
203
"fake_message" ,
198
204
"DAPR_FAKE_TAG" ,
205
+ "some_category" ,
199
206
).
200
207
WithErrorInfo (reason , metadata )
201
208
@@ -222,6 +229,7 @@ func TestErrorBuilder_WithDetails(t *testing.T) {
222
229
httpCode int
223
230
message string
224
231
tag string
232
+ category string
225
233
}
226
234
227
235
type args struct {
@@ -283,6 +291,7 @@ func TestErrorBuilder_WithDetails(t *testing.T) {
283
291
test .fields .httpCode ,
284
292
test .fields .message ,
285
293
test .fields .tag ,
294
+ test .fields .category ,
286
295
).WithDetails (test .args .a ... )
287
296
288
297
assert .Equal (t , test .want , kitErr .Build ())
@@ -292,7 +301,7 @@ func TestErrorBuilder_WithDetails(t *testing.T) {
292
301
293
302
func TestWithErrorHelp (t * testing.T ) {
294
303
// Initialize the Error struct with some default values
295
- err := NewBuilder (grpcCodes .InvalidArgument , http .StatusBadRequest , "Internal error" , "INTERNAL_ERROR" )
304
+ err := NewBuilder (grpcCodes .InvalidArgument , http .StatusBadRequest , "Internal error" , "INTERNAL_ERROR" , "some_category" )
296
305
297
306
// Define test data for the help links
298
307
links := []* errdetails.Help_Link {
@@ -319,7 +328,7 @@ func TestWithErrorHelp(t *testing.T) {
319
328
320
329
func TestWithErrorFieldViolation (t * testing.T ) {
321
330
// Initialize the Error struct with some default values
322
- err := NewBuilder (grpcCodes .InvalidArgument , http .StatusBadRequest , "Internal error" , "INTERNAL_ERROR" )
331
+ err := NewBuilder (grpcCodes .InvalidArgument , http .StatusBadRequest , "Internal error" , "INTERNAL_ERROR" , "some_category" )
323
332
324
333
// Define test data for the field violation
325
334
fieldName := "testField"
@@ -348,6 +357,7 @@ func TestError_JSONErrorValue(t *testing.T) {
348
357
httpCode int
349
358
message string
350
359
tag string
360
+ category string
351
361
}
352
362
353
363
tests := []struct {
@@ -657,7 +667,7 @@ func TestError_JSONErrorValue(t *testing.T) {
657
667
658
668
for _ , test := range tests {
659
669
t .Run (test .name , func (t * testing.T ) {
660
- kitErr := NewBuilder (test .fields .grpcCode , test .fields .httpCode , test .fields .message , test .fields .tag ).
670
+ kitErr := NewBuilder (test .fields .grpcCode , test .fields .httpCode , test .fields .message , test .fields .tag , test . fields . category ).
661
671
WithDetails (test .fields .details ... )
662
672
663
673
got := kitErr .err .JSONErrorValue ()
@@ -705,6 +715,7 @@ func TestError_GRPCStatus(t *testing.T) {
705
715
httpCode int
706
716
message string
707
717
tag string
718
+ category string
708
719
}
709
720
710
721
tests := []struct {
@@ -769,6 +780,7 @@ func TestError_GRPCStatus(t *testing.T) {
769
780
test .fields .httpCode ,
770
781
test .fields .message ,
771
782
test .fields .tag ,
783
+ test .fields .category ,
772
784
).WithDetails (test .fields .details ... )
773
785
774
786
got := kitErr .err .GRPCStatus ()
@@ -787,6 +799,7 @@ func TestErrorBuilder_Build(t *testing.T) {
787
799
http .StatusTeapot ,
788
800
"Test Msg" ,
789
801
"SOME_ERROR" ,
802
+ "some_category" ,
790
803
).WithErrorInfo ("fake" , map [string ]string {"fake" : "test" }).Build ()
791
804
792
805
builtErr , ok := built .(Error )
@@ -803,6 +816,33 @@ func TestErrorBuilder_Build(t *testing.T) {
803
816
}
804
817
805
818
assert .True (t , containsErrorInfo )
819
+ assert .Equal (t , "SOME_ERROR" , builtErr .ErrorCode ())
820
+ })
821
+
822
+ t .Run ("With_ErrorInfo (legacy tag absent)" , func (t * testing.T ) {
823
+ built := NewBuilder (
824
+ grpcCodes .ResourceExhausted ,
825
+ http .StatusTeapot ,
826
+ "Test Msg" ,
827
+ "" ,
828
+ "some_category" ,
829
+ ).WithErrorInfo ("SOME_ERROR" , map [string ]string {"fake" : "test" }).Build ()
830
+
831
+ builtErr , ok := built .(Error )
832
+ require .True (t , ok )
833
+
834
+ containsErrorInfo := false
835
+
836
+ for _ , detail := range builtErr .details {
837
+ _ , isErrInfo := detail .(* errdetails.ErrorInfo )
838
+ if isErrInfo {
839
+ containsErrorInfo = true
840
+ break
841
+ }
842
+ }
843
+
844
+ assert .True (t , containsErrorInfo )
845
+ assert .Equal (t , "SOME_ERROR" , builtErr .ErrorCode ())
806
846
})
807
847
808
848
t .Run ("Without_ErrorInfo" , func (t * testing.T ) {
@@ -811,6 +851,7 @@ func TestErrorBuilder_Build(t *testing.T) {
811
851
http .StatusTeapot ,
812
852
"Test Msg" ,
813
853
"SOME_ERROR" ,
854
+ "some_category" ,
814
855
)
815
856
816
857
assert .PanicsWithValue (t , "Must include ErrorInfo in error details." , func () {
0 commit comments