You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Viktor Somogyi (JIRA)" <ji...@apache.org> on 2017/10/18 21:36:00 UTC

[jira] [Created] (KAFKA-6084) ReassignPartitionsCommand should propagate JSON parsing failures

Viktor Somogyi created KAFKA-6084:
-------------------------------------

             Summary: ReassignPartitionsCommand should propagate JSON parsing failures
                 Key: KAFKA-6084
                 URL: https://issues.apache.org/jira/browse/KAFKA-6084
             Project: Kafka
          Issue Type: Improvement
          Components: admin
    Affects Versions: 0.11.0.0
            Reporter: Viktor Somogyi
            Assignee: Viktor Somogyi
            Priority: Minor
         Attachments: Screen Shot 2017-10-18 at 23.31.22.png

Basically looking at Json.scala it will always swallow any parsing errors:
{code}
  def parseFull(input: String): Option[JsonValue] =
    try Option(mapper.readTree(input)).map(JsonValue(_))
    catch { case _: JsonProcessingException => None }
{code}

However sometimes it is easy to figure out the problem by simply looking at the JSON, in some cases it is not very trivial, such as some invisible characters (like byte order mark) won't be displayed by most of the text editors and can people spend time on figuring out what's the problem.

As Jackson provides a really detailed exception about what failed and how, it is easy to propagate the failure to the user.

As an example I attached a BOM prefixed JSON which fails with the following error which is very counterintuitive:
{noformat}
[root@localhost ~]# kafka-reassign-partitions --zookeeper localhost:2181 --reassignment-json-file /root/increase-replication-factor.json --execute
Partitions reassignment failed due to Partition reassignment data file /root/increase-replication-factor.json is empty
kafka.common.AdminCommandFailedException: Partition reassignment data file /root/increase-replication-factor.json is empty
at kafka.admin.ReassignPartitionsCommand$.executeAssignment(ReassignPartitionsCommand.scala:120)
at kafka.admin.ReassignPartitionsCommand$.main(ReassignPartitionsCommand.scala:52)
at kafka.admin.ReassignPartitionsCommand.main(ReassignPartitionsCommand.scala)
...
{noformat}

In case of the above error it would be much better to see what fails exactly:
{noformat}
kafka.common.AdminCommandFailedException: Admin command failed
	at kafka.admin.ReassignPartitionsCommand$.parsePartitionReassignmentData(ReassignPartitionsCommand.scala:267)
	at kafka.admin.ReassignPartitionsCommand$.parseAndValidate(ReassignPartitionsCommand.scala:275)
	at kafka.admin.ReassignPartitionsCommand$.executeAssignment(ReassignPartitionsCommand.scala:197)
	at kafka.admin.ReassignPartitionsCommand$.executeAssignment(ReassignPartitionsCommand.scala:193)
	at kafka.admin.ReassignPartitionsCommand$.main(ReassignPartitionsCommand.scala:64)
	at kafka.admin.ReassignPartitionsCommand.main(ReassignPartitionsCommand.scala)
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('' (code 65279 / 0xfeff)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: (String)"{"version":1,
  "partitions":[
   {"topic": "test1", "partition": 0, "replicas": [1,2]},
   {"topic": "test2", "partition": 1, "replicas": [2,3]}
]}"; line: 1, column: 2]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1798)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:663)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:561)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1892)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:747)
	at com.fasterxml.jackson.databind.ObjectMapper._readTreeAndClose(ObjectMapper.java:4030)
	at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2539)
	at kafka.utils.Json$.kafka$utils$Json$$doParseFull(Json.scala:46)
	at kafka.utils.Json$$anonfun$tryParseFull$1.apply(Json.scala:44)
	at kafka.utils.Json$$anonfun$tryParseFull$1.apply(Json.scala:44)
	at scala.util.Try$.apply(Try.scala:192)
	at kafka.utils.Json$.tryParseFull(Json.scala:44)
	at kafka.admin.ReassignPartitionsCommand$.parsePartitionReassignmentData(ReassignPartitionsCommand.scala:241)
	... 5 more
{noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)