Unify error messages

This commit is contained in:
2024-10-18 19:04:08 +02:00
parent 411cd89b7c
commit d4e7bce5e2
20 changed files with 92 additions and 110 deletions

View File

@@ -1,6 +1,6 @@
package atom
import "errors"
import "fmt"
type PlainText struct {
*CommonAttributes
@@ -15,15 +15,15 @@ func (p *PlainText) isText() bool { return true }
// error.
func (p *PlainText) Check() error {
if p.Type != "" && p.Type != "text" && p.Type != "html" {
return errors.New("type attribute of plain text must be text or html if not omitted")
return fmt.Errorf("type attribute of plain text %v must be text or html if not omitted", p)
}
if p.Type == "html" && !isCorrectlyEscaped(p.Text) {
return errors.New("text element of plain text not correctly escaped")
return fmt.Errorf("text element of plain text %v not correctly escaped", p)
}
if p.Text == "" {
return errors.New("text element of plain text empty")
return fmt.Errorf("text element of plain text %v empty", p)
}
return nil