| Addshore added a comment. |
So after reading this investigation and trying to look at the root inconsistencies I see a few things.
The formatting either:
- happens correctly, and we get something formatted
- the ValueFormatter that is used returns a FormattingException or InvalidArgumentExceptions
- an EntityIdFormatter that is wrapped in a EntityIdValueFormatter fatals due to typehints (the new case we are seeing with out lexeme code)
The EntityIdFormatter interface currently doesn't say what should happen in the situation that a bad value is passed to it, and it can not be formatted.
Conventions within wikibase probably dictate that this should be an InvalidArgumentException.
The EntityIdValueFormatter already has a small bit of code checking that the value passed is roughly the correct type:
if ( !( $value instanceof EntityIdValue ) ) {
throw new InvalidArgumentException( 'Data value type mismatch. Expected an EntityIdValue.' );
}before trying to call ->format with the internal formatter.
So if the EntityIdFormatter implementations actually threw InvalidArgumentExceptions when they know they are being given things they can't handle we would have 1 exception constantly bubbling up to deal with in the API rather than any fatals etc.
It would probably make sense for the ValueFormatter interface and the EntityIdFormatter interface to both throw their own flavour of InvalidArgumentException (although this might be overkill).
EntityIdValueFormatter could then catch one flavour and rethrow in the correct flavour (could even be a FormattingException?)
Or we just make these InvalidArgumentExceptions consistant, and just catch them in the API execute method.Thoughts?
Cc: Michael, Lucas_Werkmeister_WMDE, Addshore, Nandana, Mringgaard, Lahi, Gq86, GoranSMilovanovic, QZanden, LawExplorer, _jensen, Jonas, Wikidata-bugs, aude, Lydia_Pintscher, Darkdadaah, Mbch331
_______________________________________________ Wikidata-bugs mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs
