From 97aa713cc441c0ecd78d9f9f8b5c4f50c9dbe048 Mon Sep 17 00:00:00 2001 From: Jimmy Lu Date: Wed, 23 Oct 2024 15:33:09 -0700 Subject: [PATCH] Make RowType::nameOf throw Velox exception (#11336) Summary: Pull Request resolved: https://github.com/facebookincubator/velox/pull/11336 So we can have a stacktrace and easier to debug. Reviewed By: bikramSingh91 Differential Revision: D64845329 fbshipit-source-id: 4677589e21e8cf71d0112e886b5af56d89e88267 --- velox/type/Type.h | 3 ++- velox/type/tests/TypeTest.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/velox/type/Type.h b/velox/type/Type.h index 40e00ecd2511..878ca2512851 100644 --- a/velox/type/Type.h +++ b/velox/type/Type.h @@ -1014,7 +1014,8 @@ class RowType : public TypeBase { std::optional getChildIdxIfExists(const std::string& name) const; const std::string& nameOf(uint32_t idx) const { - return names_.at(idx); + VELOX_CHECK_LT(idx, names_.size()); + return names_[idx]; } bool equivalent(const Type& other) const override; diff --git a/velox/type/tests/TypeTest.cpp b/velox/type/tests/TypeTest.cpp index 1bf8d6d384e5..a3ab45a962cd 100644 --- a/velox/type/tests/TypeTest.cpp +++ b/velox/type/tests/TypeTest.cpp @@ -413,7 +413,7 @@ TEST(TypeTest, row) { EXPECT_STREQ(row0->findChild("a")->kindName(), "INTEGER"); EXPECT_EQ(row0->nameOf(0), "a"); EXPECT_EQ(row0->nameOf(1), "b"); - EXPECT_THROW(row0->nameOf(4), std::out_of_range); + EXPECT_THROW(row0->nameOf(4), VeloxRuntimeError); EXPECT_THROW(row0->findChild("not_exist"), VeloxUserError); // todo: expected case behavior?: VELOX_ASSERT_THROW(