-
Notifications
You must be signed in to change notification settings - Fork 15.2k
KAFKA-4709:Error message from Struct.validate() should include the name of the offending field. #2521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KAFKA-4709:Error message from Struct.validate() should include the name of the offending field. #2521
Changes from all commits
dce515e
1465cf4
2380425
24d6ea3
b6c3156
5fbff06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,9 +207,14 @@ public Schema valueSchema() { | |
| * @param value value to test | ||
| */ | ||
| public static void validateValue(Schema schema, Object value) { | ||
| validateValue(null, schema, value); | ||
| } | ||
|
|
||
| public static void validateValue(String name, Schema schema, Object value) { | ||
| 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 | ||
| + "\", schema type: " + schema.type()); | ||
| else | ||
| return; | ||
| } | ||
|
|
@@ -220,7 +225,9 @@ public static void validateValue(Schema schema, Object value) { | |
| expectedClasses = SCHEMA_TYPE_CLASSES.get(schema.type()); | ||
|
|
||
| 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() | ||
| + ": " + value.getClass() | ||
| + " for field: \"" + name + "\""); | ||
|
|
||
| boolean foundMatch = false; | ||
| for (Class<?> expectedClass : expectedClasses) { | ||
|
|
@@ -230,7 +237,9 @@ public static void validateValue(Schema schema, Object value) { | |
| } | ||
| } | ||
| 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() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message is updated to say "required field". Do we actually know that this is a required field here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have removed "required" from error message. we can judge if it's required field from |
||
| + ": " + value.getClass() | ||
| + " for field: \"" + name + "\""); | ||
|
|
||
| switch (schema.type()) { | ||
| case STRUCT: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| package org.apache.kafka.connect.data; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class FakeSchema implements Schema { | ||
| @Override | ||
| public Type type() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isOptional() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public Object defaultValue() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return "fake"; | ||
| } | ||
|
|
||
| @Override | ||
| public Integer version() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public String doc() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> parameters() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Schema keySchema() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Schema valueSchema() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Field> fields() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Field field(String fieldName) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Schema schema() { | ||
| return null; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is updated to say "required field". Do we actually know that this is a required field here?