Skip to content
This repository was archived by the owner on Nov 21, 2023. It is now read-only.

Commit f430647

Browse files
Merge pull request #3 from goinsane/develop
v1.0.1
2 parents 3c61724 + 048e235 commit f430647

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

erf.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ func (e *Erf) Attach(tags ...string) *Erf {
154154
return e
155155
}
156156

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.
158158
func (e *Erf) Tag(tag string) interface{} {
159159
index := -1
160160
if idx, ok := e.tagIndexes[tag]; ok {
161161
index = idx
162162
}
163163
if index < 0 || index >= e.Len() {
164-
panic("tag not found")
164+
return nil
165165
}
166166
return e.args[index]
167167
}
@@ -195,13 +195,19 @@ func newf(format string, args ...interface{}) *Erf {
195195
e := &Erf{
196196
err: fmt.Errorf(format, args...),
197197
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)
199205
}
200-
copy(e.args, args)
201206
return e
202207
}
203208

204209
// Newf creates a new Erf object with the given format and args.
210+
// It panics if an arg is nil.
205211
func Newf(format string, args ...interface{}) *Erf {
206212
e := newf(format, args...)
207213
e.initialize(4)
@@ -216,6 +222,7 @@ func Errorf(format string, a ...interface{}) error {
216222
}
217223

218224
// 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.
219226
func Wrap(err error) error {
220227
e := newf("%w", err)
221228
e.initialize(4)

interfaces.go renamed to ifcs.go

File renamed without changes.

util.go renamed to utils.go

File renamed without changes.

0 commit comments

Comments
 (0)