[ 
https://issues.apache.org/jira/browse/KAFKA-6084?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16210101#comment-16210101
 ] 

ASF GitHub Bot commented on KAFKA-6084:
---------------------------------------

GitHub user viktorsomogyi opened a pull request:

    https://github.com/apache/kafka/pull/4090

    [KAFKA-6084] Propagate JSON parsing errors in ReassignPartitionsCommand

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/viktorsomogyi/kafka KAFKA-6084

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/kafka/pull/4090.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #4090
    
----
commit 3f1a24014e022ad351ea669ba73efa645ccca5f3
Author: Viktor Somogyi <viktorsomo...@gmail.com>
Date:   2017-10-14T11:16:35Z

    [KAFKA-6084] Propagate JSON parsing errors in ReassignPartitionsCommand

----


> 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
>              Labels: easyfix, newbie
>         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)

Reply via email to