Skip to content

Commit

Permalink
Skip empty fields in Error() (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-- authored Jan 10, 2022
1 parent 38c1411 commit e172f4d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions xattr.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,29 @@ type Error struct {
Err error
}

func (e *Error) Error() string {
return e.Op + " " + e.Path + " " + e.Name + ": " + e.Err.Error()
func (e *Error) Error() (errstr string) {
if e.Op != "" {
errstr += e.Op
}
if e.Path != "" {
if errstr != "" {
errstr += " "
}
errstr += e.Path
}
if e.Name != "" {
if errstr != "" {
errstr += " "
}
errstr += e.Name
}
if e.Err != nil {
if errstr != "" {
errstr += ": "
}
errstr += e.Err.Error()
}
return
}

// Get retrieves extended attribute data associated with path. It will follow
Expand Down

0 comments on commit e172f4d

Please sign in to comment.