diff options
| author | dev | 2026-06-26 13:19:02 +0200 |
|---|---|---|
| committer | dev | 2026-06-26 13:19:02 +0200 |
| commit | 64ef4e5f48e31e3f003fd4abf0c499e87beb3c43 (patch) | |
| tree | 7512422d9a8795010d875608687aa1e0556bb486 | |
| parent | ef75353f3710d7566aa8b41922f776ecb3968830 (diff) | |
| download | hnimdbbot-64ef4e5f48e31e3f003fd4abf0c499e87beb3c43.tar.gz | |
fix: add nil checks in extractPeople for missing infobox/section data
- Guard section.has_parts type assertion in extractPeople
- Guard Cast section has_parts iteration with ok check
| -rw-r--r-- | src/wikiarticle.go | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/wikiarticle.go b/src/wikiarticle.go index cef9f02..c1ce486 100644 --- a/src/wikiarticle.go +++ b/src/wikiarticle.go @@ -234,32 +234,34 @@ func extractPeople(article map[string]interface{}) []wikiPerson { people = append(people, extractPersonFromField(fp, 3)...) } } - // Actors from Cast section for _, sec := range getSections(article) { s, ok := sec.(map[string]interface{}) if !ok || s["name"] != "Cast" { continue } - for _, part := range s["has_parts"].([]interface{}) { - p, ok := part.(map[string]interface{}) - if !ok || p["type"] != "list" { - continue - } - for _, item := range p["has_parts"].([]interface{}) { - item, ok := item.(map[string]interface{}) - if !ok { + if hp, ok := s["has_parts"].([]interface{}); ok { + for _, part := range hp { + p, ok := part.(map[string]interface{}) + if !ok || p["type"] != "list" { continue } - if link, ok := getFirstPersonLink(item); ok { - people = append(people, wikiPerson{Name: link, Profession: 1}) + if items, ok := p["has_parts"].([]interface{}); ok { + for _, item := range items { + item, ok := item.(map[string]interface{}) + if !ok { + continue + } + if link, ok := getFirstPersonLink(item); ok { + people = append(people, wikiPerson{Name: link, Profession: 1}) + } + } } + break // only first list in Cast section } - break // only first list in Cast section } break // only Cast section } - return people } @@ -281,7 +283,10 @@ func getInfoboxParts(article map[string]interface{}) []interface{} { if !ok { return nil } - return section["has_parts"].([]interface{}) + if hp, ok := section["has_parts"].([]interface{}); ok { + return hp + } + return nil } // getSections returns sections from the article. |
