Skip to content

Commit 54ebc02

Browse files
Improve error message when number of elements is not divisible by divisor.
PiperOrigin-RevId: 648085047
1 parent 134ec6f commit 54ebc02

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tensorflow/core/util/example_proto_fast_parsing.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ limitations under the License.
2222

2323
#include "absl/base/casts.h"
2424
#include "absl/container/flat_hash_map.h"
25+
#include "absl/status/status.h"
26+
#include "absl/strings/substitute.h"
2527
#include "tensorflow/core/example/example.pb.h"
2628
#include "tensorflow/core/example/feature.pb.h"
2729
#include "tensorflow/core/framework/allocator.h"
@@ -1718,7 +1720,10 @@ Status FastParseSingleExample(const Config& config, StringPiece serialized,
17181720
}
17191721

17201722
if (num_elements % num_elements_divisor != 0) {
1721-
return parse_error();
1723+
return absl::InvalidArgumentError(absl::Substitute(
1724+
"Error while parsing feature with key $0: number "
1725+
"of elements should be divisible by $1, found $2 instead",
1726+
feature_name, num_elements_divisor, num_elements));
17221727
}
17231728

17241729
if (stats) {

tensorflow/python/kernel_tests/io_ops/parse_single_example_op_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ def testSerializedContainingVarLenDense(self):
810810
}
811811
},
812812
# TODO(mrry): Consider matching the `io.parse_example()` error message.
813-
expected_err=(errors_impl.OpError, "Key: b."))
813+
expected_err=(errors_impl.OpError, "key b:"))
814814

815815
self._test(
816816
{

0 commit comments

Comments
 (0)