ProfessionalWiki / EDTF

PHP library to parse, represent and work with dates that follow the Extended Date/Time Format specification.
https://wikibase.consulting/wikibase-edtf
GNU General Public License v2.0
10 stars 7 forks source link

Expose validation errors #66

Closed seth-shaw-unlv closed 3 years ago

seth-shaw-unlv commented 3 years ago

I can see reading through the code that the validator is generating messages about why a provided string is considered an invalid ETDF... however, the ParsingResult I can get from the SaneParser and Validator available from the EDTF factory doesn't even get a copy of them; instead it only gives us isValid() based on the existence of an EdtfValue (or lack thereof) from the SaneParser which swallows the InvalidArgumentException.

I need to give my users some clue as to why I'm rejecting the EDTF string they entered. Could we get those messages propagated to the ParsingResult? Or, failing that, as a developer I would rather catch the InvalidArgumentException than have it swallowed and reduced to a boolean response.

seth-shaw-unlv commented 3 years ago

Well, I guess I can simply bypass the factory SaneParser and instantiate a Parser myself...

JeroenDeDauw commented 3 years ago

Making the exception message available in ParsingResult makes sense. https://github.com/ProfessionalWiki/EDTF/blob/master/src/PackagePrivate/SaneParser.php#L18-L19

While you could use Parser directly, that thing is a handful to deal with, and it is not part of the public interface of the library, so you'd not be able to upgrade minor versions safely.

seth-shaw-unlv commented 3 years ago

Thanks. I'll work with the Parser directly for validation for the time being but then switch back to using the factory once we have a version where I can get those messages.

JeroenDeDauw commented 3 years ago

@seth-shaw-unlv master and ~1.3.0 (not tagged yet) now support access to the error message in ParsingResult