@@ -25,7 +25,7 @@ import (
25
25
)
26
26
27
27
func TestError (t * testing.T ) {
28
- e := Error (Utility , UtilityUnknownError )
28
+ e := Error (" Utility" , "ErrorWithArg" , "An unknown error occurred." )
29
29
s := e .GetStack ()
30
30
if s != "" {
31
31
t .Fatalf ("No error stack should have been recorded." )
@@ -34,15 +34,15 @@ func TestError(t *testing.T) {
34
34
35
35
// TestErrorWithArg tests creating an error with a message argument
36
36
func TestErrorWithArg (t * testing.T ) {
37
- e := Error (Utility , UtilityErrorWithArg , "arg1" )
37
+ e := Error (" Utility" , "ErrorWithArg" , "An error occurred: %s" , "arg1" )
38
38
s := e .GetStack ()
39
39
if s != "" {
40
40
t .Fatalf ("No error stack should have been recorded." )
41
41
}
42
42
}
43
43
44
44
func TestErrorWithCallstack (t * testing.T ) {
45
- e := ErrorWithCallstack (Utility , UtilityUnknownError )
45
+ e := ErrorWithCallstack (" Utility" , "UnknownError" , "An unknown error occurred." )
46
46
s := e .GetStack ()
47
47
if s == "" {
48
48
t .Fatalf ("No error stack was recorded." )
@@ -52,7 +52,7 @@ func TestErrorWithCallstack(t *testing.T) {
52
52
// TestErrorWithCallstackAndArg tests creating an error with a callstack and
53
53
// message argument
54
54
func TestErrorWithCallstackAndArg (t * testing.T ) {
55
- e := ErrorWithCallstack (Utility , UtilityErrorWithArg , "arg1" )
55
+ e := ErrorWithCallstack (" Utility" , "ErrorWithArg" , "An error occurred: %s" , "arg1" )
56
56
s := e .GetStack ()
57
57
if s == "" {
58
58
t .Fatalf ("No error stack was recorded." )
@@ -67,7 +67,7 @@ func TestErrorWithCallstackMessage(t *testing.T) {
67
67
// to the error message
68
68
flogging .SetModuleLevel ("error" , "debug" )
69
69
70
- e := ErrorWithCallstack (Utility , UtilityUnknownError )
70
+ e := ErrorWithCallstack (" Utility" , "ErrorWithArg" , "An unknown error occurred." )
71
71
s := e .GetStack ()
72
72
if s == "" {
73
73
t .Fatalf ("No error stack was recorded." )
@@ -85,73 +85,67 @@ func ExampleError() {
85
85
// not be appended to the error message
86
86
flogging .SetModuleLevel ("error" , "warning" )
87
87
88
- err := ErrorWithCallstack (Utility , UtilityUnknownError )
88
+ err := ErrorWithCallstack (" Utility" , "UnknownError" , "An unknown error occurred." )
89
89
90
90
if err != nil {
91
91
fmt .Printf ("%s\n " , err .Error ())
92
92
fmt .Printf ("%s\n " , err .GetErrorCode ())
93
93
fmt .Printf ("%s\n " , err .GetComponentCode ())
94
94
fmt .Printf ("%s\n " , err .GetReasonCode ())
95
95
fmt .Printf ("%s\n " , err .Message ())
96
- fmt .Printf ("%s\n " , err .MessageIn ("en" ))
97
96
// Output:
98
97
// An unknown error occurred.
99
- // Utility-UtilityUnknownError
98
+ // Utility-UnknownError
100
99
// Utility
101
- // UtilityUnknownError
102
- // An unknown error occurred.
100
+ // UnknownError
103
101
// An unknown error occurred.
104
102
}
105
103
}
106
104
107
105
// ExampleErrorWithArg tests the output for a sample error with a message
108
106
// argument
109
- func ExampleUtilityErrorWithArg () {
107
+ func Example_utilityErrorWithArg () {
110
108
// when the 'error' module is set to anything but debug, the callstack will
111
109
// not be appended to the error message
112
110
flogging .SetModuleLevel ("error" , "warning" )
113
111
114
- err := ErrorWithCallstack (Utility , UtilityErrorWithArg , "arg1" )
112
+ err := ErrorWithCallstack (" Utility" , "ErrorWithArg" , "An error occurred: %s" , "arg1" )
115
113
116
114
if err != nil {
117
115
fmt .Printf ("%s\n " , err .Error ())
118
116
fmt .Printf ("%s\n " , err .GetErrorCode ())
119
117
fmt .Printf ("%s\n " , err .GetComponentCode ())
120
118
fmt .Printf ("%s\n " , err .GetReasonCode ())
121
119
fmt .Printf ("%s\n " , err .Message ())
122
- fmt .Printf ("%s\n " , err .MessageIn ("en" ))
123
120
// Output:
124
121
// An error occurred: arg1
125
- // Utility-UtilityErrorWithArg
122
+ // Utility-ErrorWithArg
126
123
// Utility
127
- // UtilityErrorWithArg
128
- // An error occurred: arg1
124
+ // ErrorWithArg
129
125
// An error occurred: arg1
130
126
}
131
127
}
132
128
133
- // ExampleLoggingInvalidLogLevel tests the output for a logging error where
129
+ // Example_loggingInvalidLevel tests the output for a logging error where
134
130
// and an invalid log level has been provided
135
- func ExampleLoggingInvalidLogLevel () {
131
+ func Example_loggingInvalidLevel () {
136
132
// when the 'error' module is set to anything but debug, the callstack will
137
133
// not be appended to the error message
138
134
flogging .SetModuleLevel ("error" , "warning" )
139
135
140
- err := ErrorWithCallstack (Logging , LoggingInvalidLogLevel , "invalid" )
136
+ err := ErrorWithCallstack (" Logging" , "InvalidLevel" , "Invalid log level provided - %s" , "invalid" )
141
137
142
138
if err != nil {
143
139
fmt .Printf ("%s\n " , err .Error ())
144
140
fmt .Printf ("%s\n " , err .GetErrorCode ())
145
141
fmt .Printf ("%s\n " , err .GetComponentCode ())
146
142
fmt .Printf ("%s\n " , err .GetReasonCode ())
147
143
fmt .Printf ("%s\n " , err .Message ())
148
- fmt .Printf ("%s\n " , err .MessageIn ("en" ))
149
144
// Output:
150
145
// Invalid log level provided - invalid
151
- // Logging-LoggingInvalidLogLevel
146
+ // Logging-InvalidLevel
152
147
// Logging
153
- // LoggingInvalidLogLevel
154
- // Invalid log level provided - invalid
148
+ // InvalidLevel
155
149
// Invalid log level provided - invalid
156
150
}
157
151
}
0 commit comments