amugofjava / podcast_search

A simple library providing programmatic access to the iTunes search API for podcasts.
MIT License
41 stars 26 forks source link

Error parsing search response #20

Closed jennie-metacast closed 5 months ago

jennie-metacast commented 5 months ago

For some reason, when I search for the term Jenny, the podcast_search package has an internal error.

My guess is that one of the results in the response has something unexpected (null where it should be String). The StackTrace is pointing to this line.

Example code:

final podcastSearch = Search();
final result = await podcastSearch.search('Jenny');

Example StackTrace:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'String'
#0      Item._fromItunes (package:podcast_search/src/model/item.dart:148:39)
#1      new Item.fromJson (package:podcast_search/src/model/item.dart:120:11)
#2      new SearchResult.fromJson.<anonymous closure> (package:podcast_search/src/model/search_result.dart:85:25)
#3      MappedListIterable.elementAt (dart:_internal/iterable.dart:425:31)
#4      ListIterator.moveNext (dart:_internal/iterable.dart:354:26)
#5      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#6      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#7      new List.of (dart:core-patch/array_patch.dart:39:18)
amugofjava commented 5 months ago

Hi @jennie-metacast,

One of the items within the search results does not have a release date field within the JSON, causing the date parsing to fail. The podcast in question is Headspin:

https://podcasts.apple.com/us/podcast/headspin/id1533597561?uo=4

This podcast does not have a release date as it currently has no episodes.

I hadn't considered podcasts with zero episodes, so thank you for spotting this. Should be fairly quick to fix and push an update to pub.dev.

amugofjava commented 5 months ago

Hi @jennie-metacast,

I have fixed this bug and pushed v0.6.9 to pub.dev