Unify error messages
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/mail"
|
||||
)
|
||||
@@ -33,25 +32,25 @@ func (p *Person) AddExtension(e *ExtensionElement) {
|
||||
// error.
|
||||
func (p *Person) Check() error {
|
||||
if p.Name == "" {
|
||||
return errors.New("name element of person element empty")
|
||||
return fmt.Errorf("name element of person %v empty", p)
|
||||
}
|
||||
|
||||
if p.URI != "" {
|
||||
if !isValidIRI(p.URI) {
|
||||
return fmt.Errorf("uri element of person %v not correctly formatted", p.Name)
|
||||
return fmt.Errorf("uri element of person %v not correctly formatted", p)
|
||||
}
|
||||
}
|
||||
|
||||
if p.Email != "" {
|
||||
if _, err := mail.ParseAddress(string(p.Email)); err != nil {
|
||||
return fmt.Errorf("email element of person %v not correctly formatted", p.Name)
|
||||
return fmt.Errorf("email element of person %v not correctly formatted", p)
|
||||
}
|
||||
}
|
||||
|
||||
if p.Extensions != nil {
|
||||
for i, e := range p.Extensions {
|
||||
if err := e.Check(); err != nil {
|
||||
return fmt.Errorf("extension element %v of person %v: %v", i, p.Name, err)
|
||||
return fmt.Errorf("extension element %v of person %v: %v", i, p, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user