Skip to content

Commit

Permalink
remove uneeded *Link casting
Browse files Browse the repository at this point in the history
  • Loading branch information
deankarn committed Apr 2, 2018
1 parent 2e21ac3 commit ba974b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
10 changes: 4 additions & 6 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c Chain) Error() string {
lines := make([]string, 0, len(c))
// source=<source> <prefix>: <error> tag=value tag2=value2 types=type1,type2
for i := len(c) - 1; i >= 0; i-- {
line := c[i].Error()
line := c[i].formatError()
lines = append(lines, line)
}
return strings.Join(lines, "\n")
Expand All @@ -60,17 +60,15 @@ type Link struct {
Source string
}

// Error prints a single Links error
func (l *Link) Error() string {
// formatError prints a single Links error
func (l *Link) formatError() string {
line := fmt.Sprintf("source=%s ", l.Source)

if l.Prefix != "" {
line += l.Prefix + ": "
}

if _, isLink := l.Err.(*Link); !isLink {
line += l.Err.Error()
}
line += l.Err.Error()

for _, tag := range l.Tags {
line += fmt.Sprintf(" %s=%v", tag.Key, tag.Value)
Expand Down
14 changes: 0 additions & 14 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ func Cause(err error) error {
switch t := err.(type) {
case Chain:
return t[0].Err
case *Link:
return t.Err
default:
return err
}
Expand All @@ -66,12 +64,6 @@ func HasType(err error, typ string) bool {
}
}
}
case *Link:
for i := 0; i < len(t.Types); i++ {
if t.Types[i] == typ {
return true
}
}
}
return false
}
Expand All @@ -87,12 +79,6 @@ func LookupTag(err error, key string) interface{} {
}
}
}
case *Link:
for i := 0; i < len(t.Tags); i++ {
if t.Tags[i].Key == key {
return t.Tags[i].Value
}
}
}
return nil
}

0 comments on commit ba974b9

Please sign in to comment.