Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TVDB Deserialization Error #111

Closed
crobibero opened this issue Feb 27, 2024 · 7 comments
Closed

TVDB Deserialization Error #111

crobibero opened this issue Feb 27, 2024 · 7 comments
Labels
bug This PR or Issue describes or fixes something that isn't working

Comments

@crobibero
Copy link
Member

#106 (comment)

Tvdb.Sdk.SearchException: Could not deserialize the response body stream as Tvdb.Sdk.Response45.

Status: 200
Response: 

 ---> System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $.data[0].movie.runtime | LineNumber: 0 | BytePositionInLine: 281.
 ---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a number.
   at System.Text.Json.Utf8JsonReader.TryGetInt32(Int32& value)
   at System.Text.Json.Utf8JsonReader.GetInt32()
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonReaderState& readerState, Boolean isFinalBlock, ReadOnlySpan`1 buffer, JsonSerializerOptions options, ReadStack& state, JsonConverter converterBase)
   at System.Text.Json.JsonSerializer.ContinueDeserialize[TValue](ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, JsonConverter converter, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.ReadAllAsync[TValue](Stream utf8Json, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken)
   at Tvdb.Sdk.SearchClient.ReadObjectResponseAsync[T](HttpResponseMessage response, IReadOnlyDictionary`2 headers, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Tvdb.Sdk.SearchClient.ReadObjectResponseAsync[T](HttpResponseMessage response, IReadOnlyDictionary`2 headers, CancellationToken cancellationToken)
   at Tvdb.Sdk.SearchClient.GetSearchResultsByRemoteIdAsync(String remoteId, CancellationToken cancellationToken)
   at Jellyfin.Plugin.Tvdb.TvdbClientManager.GetSeriesByRemoteIdAsync(String remoteId, String language, CancellationToken cancellationToken)
...

#106 (comment)

Can be tested with id 253323

seriesClient.GetSeriesExtendedAsync(id: 253323, meta: null, @short: true);

Fixes will need to be made upstream

@crobibero crobibero added the bug This PR or Issue describes or fixes something that isn't working label Feb 27, 2024
@scampower3
Copy link
Member

scampower3 commented Feb 27, 2024

Hey, letting you know that response45 indicates an issue with the GetSearchResultsByRemoteIdAsync method.

Can be tested with id 253323

seriesClient.GetSeriesExtendedAsync(id: 253323, meta: null, @short: true);

Fixes will need to be made upstream

Testing with 253323 results in a different serialization issue (response55) which I appended to my original bug report in the upstream.

@BobSilent
Copy link
Contributor

during my testing i saw these three issues (with a small series library)

            var seriesClient = provider.GetService<ISeriesClient>();
            // Error: Could not deserialize the response body stream as Tvdb.Sdk.Response55.
            var seriesResult = await seriesClient.GetSeriesExtendedAsync(id: 253323, meta: null, @short: true);
            var searchClient = provider.GetService<ISearchClient>();
            // Error: Could not deserialize the response body stream as Tvdb.Sdk.Response45.
            var searchResult = await searchClient.GetSearchResultsByRemoteIdAsync("62702");
            var episodesClient = provider.GetService<IEpisodesClient>();
            // Error: Could not deserialize the response body stream as Tvdb.Sdk.Response20.
            var episodesResult = await episodesClient.GetEpisodeExtendedAsync(8273932);

@BobSilent
Copy link
Contributor

I saw that in some places the plugin code, at least catches client exceptions and returns and empty or null value.

So i would create an PR to do this at least for the mention code paths above.
I know this is no real fix, but at least it makes the plugin more stable and the exception is handled in the plugin and not passed on to the server.

@scampower3
Copy link
Member

scampower3 commented Feb 27, 2024

during my testing i saw these three issues (with a small series library)

            var seriesClient = provider.GetService<ISeriesClient>();
            // Error: Could not deserialize the response body stream as Tvdb.Sdk.Response55.
            var seriesResult = await seriesClient.GetSeriesExtendedAsync(id: 253323, meta: null, @short: true);
            var searchClient = provider.GetService<ISearchClient>();
            // Error: Could not deserialize the response body stream as Tvdb.Sdk.Response45.
            var searchResult = await searchClient.GetSearchResultsByRemoteIdAsync("62702");
            var episodesClient = provider.GetService<IEpisodesClient>();
            // Error: Could not deserialize the response body stream as Tvdb.Sdk.Response20.
            var episodesResult = await episodesClient.GetEpisodeExtendedAsync(8273932);

Hey for these 3 problems will be fixed when thetvdb/v4-api#318 is merged.

@BobSilent
Copy link
Contributor

and another one

            var searchClient = provider.GetService<ISearchClient>();
            // Error: Could not deserialize the response body stream as Tvdb.Sdk.Response45.
            var searchResult = await searchClient.GetSearchResultsByRemoteIdAsync("tt3121722");

System.Int32. Path: $.data[0].episode.number

@scampower3
Copy link
Member

Hey @crobibero, setting "generateOptionalPropertiesAsNullable": true in the nswag,json will fix all the serialization issues mentioned in here.

@crobibero
Copy link
Member Author

@scampower3 thank you for looking into this further, I've published 4.7.9.1 that contains this change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This PR or Issue describes or fixes something that isn't working
Projects
None yet
Development

No branches or pull requests

3 participants