Page MenuHomePhabricator

action=wbeditentity: Missing datavalue key for snaks should raise a more specified message
Closed, ResolvedPublic

Description

When a json for action=wbeditentity contains a snak, but that snak has no datavalue key the following error is given:

{code=internal_api_error_InvalidArgumentException, info=Exception Caught: Wikibase\SnakObject::newFromType got an array with to few constructor arguments}

The validation of the json should give a better error here to see the cause of the exception, instead of looking at the source.

Details

Reference
bz57768

Event Timeline

bzimport raised the priority of this task from to Normal.
bzimport set Reference to bz57768.
bzimport added a subscriber: Unknown Object (MLST).

Could you provide some params that when passed to the api reproduce this?

Be creative: {"claims":[{"type":"statement","mainsnak":{"snaktype":"value","property":"P1"},"rank":"normal"}]}
for an existing item.

Only remove the datavalue from the input. There are maybe more possible combination, all should result in a proper error message and not in an api internal error. Maybe along to ::newFromType a ::isValidInput/::canCreateTypeFromInput or so is needed to do this, which calls internal the same stack than the type would do.

When catching the internal error there is no way to know the missing json key, which would be a nice information for the client.

Lydia_Pintscher removed a subscriber: Unknown Object (MLST).
Lydia_Pintscher removed a subscriber: Unknown Object (MLST).
Lucie added a subscriber: Lucie.Dec 2 2014, 4:15 PM

I get a similar error.

{
  "servedby": "mw1017",
  "error": {
      "code": "internal_api_error_InvalidArgumentException",
      "info": "Exception Caught: Wikibase\\Lib\\Serializers\\SnakSerializer::newSnakFromType got an array with to few constructor arguments",
      "*": ""
  }
}
Lucie removed a project: TestMe.Dec 2 2014, 4:15 PM
Lucie set Security to None.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 4 2015, 9:59 PM

got an array with to few constructor arguments

Well, just looking at this and not the code we could simply also say what is expected in this exception?
Or the one that we have detected is missing?

Really this should then also be caught and returned as a UsageException..

samuwmde lowered the priority of this task from Normal to Lowest.Feb 15 2018, 4:40 PM
samuwmde added a project: patch-welcome.
samuwmde moved this task from incoming to ready to go on the Wikidata board.
matej_suchanek closed this task as Resolved.Oct 26 2018, 5:05 PM
matej_suchanek updated the task description. (Show Details)