Check first if there are any extension elements before checking them individually

This commit is contained in:
Jason Streifling 2024-10-15 16:07:11 +02:00
parent 2a4adec6bd
commit 3929892602

View File

@ -18,9 +18,11 @@ func (p *Person) Check() error {
return errors.New("name element of person element empty")
}
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)
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)
}
}
}