KAFKA-4709:Error message from Struct.validate() should include the name of the offending field.#2521
KAFKA-4709:Error message from Struct.validate() should include the name of the offending field.#2521Aegeaner wants to merge 6 commits intoapache:trunkfrom Aegeaner:KAFKA-4709
Conversation
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
| try { | ||
| ConnectSchema.validateValue(fieldSchema, value); | ||
| } catch(DataException e) { | ||
| throw new DataException("Invalid value: null used for required field: " + field.name() + ", schema type: " + fieldSchema.type()); |
There was a problem hiding this comment.
While current implementation of validateValue only throws DataException when a required field has null value, in general we may have other exception in the future, right? Then it may be misleading to claim that "null used for required field" here. Maybe you can do throw new DataException(..., e) here.
There was a problem hiding this comment.
yes, I will keep the original exception message and add some additional field info on it.
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
| try { | ||
| ConnectSchema.validateValue(fieldSchema, value); | ||
| } catch(DataException e) { | ||
| throw new DataException("Validate failed for required field: \"" + field.name() + "\", " |
There was a problem hiding this comment.
Strictly speaking you don't know whether this is a required field here. Also, you probably don't need to print e.getMessage() again since the exception have already included this message by including e in the newly constructed exception.
Actually, if all you need is the field name, would it be simpler to just keep the Struct.java as it is, and change ConnectSchema.java to do throw new DataException("Invalid value: null used for required field " + schema.name())
There was a problem hiding this comment.
this is also my first intuition here, but schema.name() returns null here. And also, schema name is not field name.
There was a problem hiding this comment.
Throwing new DataException(..., e) doesnet include original exception message, but only set up original exception as the cause in new exception. @lindong28
There was a problem hiding this comment.
@Aegeaner Yeah the original exception message is included as cause and will be printed to the log or console when the exception is thrown. That is why I think the 2nd exception includes the original exception message. I thought this is enough for user.
Also, I see your point that schema.name() is null. Would it be more precise to remove required from the 2nd exception message? Another alternative is to include an identifier (e.g. schema field name) as a parameter to validateValue(...) so that this method can identify the field with problem in the exception message. Doing this allows us to identify the field in all scenarios where validateValue(...) failed. But this also requires more change so you may want to do this only if a committer suggested so.
There was a problem hiding this comment.
@lindong28 yeah validateValue(..) method is more primitive so not that easy to change
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
@Aegeaner @lindong28 I'd suggest change the signature of |
|
@guozhangwang It's not a public API but is used quite often in connect schema tests. Kafka Connect exposed REST api to validate configs. |
|
@Aegeaner I understand. If possible we an just change its usage in all the unit test as well. |
|
@guozhangwang @Aegeaner I am not sure if we can simply change the method signature to be |
|
@lindong28 Sounds good to me. |
|
@lindong28 @guozhangwang Thanks for your advice. I have changed |
| if (value == null) { | ||
| if (!schema.isOptional()) | ||
| throw new DataException("Invalid value: null used for required field"); | ||
| throw new DataException("Invalid value null used for required field: \"" + name |
There was a problem hiding this comment.
nits: not sure if we should : after Invalid value in the error message. Otherwise LGTM.
Thanks for the update.
There was a problem hiding this comment.
@lindong28 Thanks, I have added field info to all DataException message in validateValue(..).
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
|
||
| if (expectedClasses == null) | ||
| throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); | ||
| throw new DataException("Invalid Java object for schema type " + schema.type() |
There was a problem hiding this comment.
The error message is updated to say "required field". Do we actually know that this is a required field here?
| } | ||
| if (!foundMatch) | ||
| throw new DataException("Invalid Java object for schema type " + schema.type() + ": " + value.getClass()); | ||
| throw new DataException("Invalid Java object for schema type " + schema.type() |
There was a problem hiding this comment.
The error message is updated to say "required field". Do we actually know that this is a required field here?
There was a problem hiding this comment.
I have removed "required" from error message. we can judge if it's required field from schema.isOptional() , but we may don't care about it when the value is not null.
|
Added |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
Refer to this link for build results (access rights to CI server needed): |
|
looks good to me overall. @lindong28 do you want to take another look? |
|
@guozhangwang @Aegeaner Thank you. LGTM. |
|
Merged to trunk. |
…me of the offending field. https://issues.apache.org/jira/browse/KAFKA-4709 Author: Aegeaner <xihuke@gmail.com> Reviewers: Dong Lin, Guozhang Wang Closes apache#2521 from Aegeaner/KAFKA-4709
https://issues.apache.org/jira/browse/KAFKA-4709