@@ -154,14 +154,14 @@ func (e *Erf) Attach(tags ...string) *Erf {
154
154
return e
155
155
}
156
156
157
- // Tag returns an argument value on the given tag. It panics if tag is not found.
157
+ // Tag returns an argument value on the given tag. It returns nil if tag is not found.
158
158
func (e * Erf ) Tag (tag string ) interface {} {
159
159
index := - 1
160
160
if idx , ok := e .tagIndexes [tag ]; ok {
161
161
index = idx
162
162
}
163
163
if index < 0 || index >= e .Len () {
164
- panic ( "tag not found" )
164
+ return nil
165
165
}
166
166
return e .args [index ]
167
167
}
@@ -195,13 +195,19 @@ func newf(format string, args ...interface{}) *Erf {
195
195
e := & Erf {
196
196
err : fmt .Errorf (format , args ... ),
197
197
format : format ,
198
- args : make ([]interface {}, len (args )),
198
+ args : make ([]interface {}, 0 , len (args )),
199
+ }
200
+ for _ , arg := range args {
201
+ if arg == nil {
202
+ panic ("arg is nil" )
203
+ }
204
+ e .args = append (e .args , arg )
199
205
}
200
- copy (e .args , args )
201
206
return e
202
207
}
203
208
204
209
// Newf creates a new Erf object with the given format and args.
210
+ // It panics if an arg is nil.
205
211
func Newf (format string , args ... interface {}) * Erf {
206
212
e := newf (format , args ... )
207
213
e .initialize (4 )
@@ -216,6 +222,7 @@ func Errorf(format string, a ...interface{}) error {
216
222
}
217
223
218
224
// Wrap wraps the given error as the underlying error and returns a new Erf object as the error interface.
225
+ // It panics if err is nil.
219
226
func Wrap (err error ) error {
220
227
e := newf ("%w" , err )
221
228
e .initialize (4 )
0 commit comments