CXuesong / WikiClientLibrary

/*🌻*/ Wiki Client Library is an asynchronous MediaWiki API client library targeting modern .NET platforms
https://github.com/CXuesong/WikiClientLibrary/wiki
Apache License 2.0
82 stars 16 forks source link

‘infinite’ is an invalid DateTime #50

Closed stjohann closed 5 years ago

stjohann commented 5 years ago

Hey, first of all, great library :-)

Some wikis (most of them?) use infinite in block expiration options, among them are Dutch Wikipedia and Wikitech. Fetching SiteInfo with this library with an active block from those wikis (for me, it is a block for hosting range) returns a FormatException in my bot.

I suspect that there can also be indefinite value triggering the same error, but I don’t have administrative tools anywhere to test the theory.

Fix should be pretty simple: adding infinite as an alias to infinity where applicable. This will close stjohann/DiscordWikiBot#3 for me.

Shortened trace log:

[2019-07-15 22:16:19] [DiscordWikiBot] [Error] Exception occurred: System.AggregateException: Exceptions occured within one or more event handlers. Check InnerExceptions for details. (One or more errors occurred. (The string 'infinite' was not recognized as a valid DateTime. There is an unknown word starting at index '0'.)) ---> System.AggregateException: One or more errors occurred. (The string 'infinite' was not recognized as a valid DateTime. There is an unknown word starting at index '0'.) ---> System.FormatException: The string 'infinite' was not recognized as a valid DateTime. There is an unknown word starting at index '0'.
   at System.DateTimeParse.Parse(ReadOnlySpan`1 s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
   at System.DateTime.Parse(String s, IFormatProvider provider, DateTimeStyles styles)
   at WikiClientLibrary.Infrastructures.WikiDateTimeJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
...
CXuesong commented 5 years ago

Glad you like this library.

This is likely to be a regression introduced when I'm resolving #49 . Unfortunately I'm on trip for the rest of the week. You may consider falling back to v0.7.0-int.2 to try to mitigate the current situation.

I realized it's just a case I haven't been aware of. So I will make the change when I'm back. During this time, you may consider doing some local build (and perhaps open a PR 😉). There is currently no CI/CD so I will have to publish the package on my PC.

stjohann commented 5 years ago

For reference, these seem to be all values that are treated as infinity in MediaWiki time functions (found via codesearch): https://gerrit.wikimedia.org/g/mediawiki/core/+/cbf8446b74b616a00024ef27225bd1e12ffd3bf6/includes/GlobalFunctions.php#2990

I can do a pull request about this if that’s convenient. This is not a critical error for my library, btw, I just got to finally know the cause.