From 02d835e27424c0b305f9a6f5141b9d4976a9943e Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 18:14:26 +0800 Subject: [PATCH 01/19] [enhancement](exception) add exception structure --- be/src/common/exception.cpp | 48 ++++++++++++ be/src/common/exception.h | 76 +++++++++++++++++++ .../exprs/table_function/vexplode_bitmap.cpp | 13 +--- .../exprs/table_function/vexplode_bitmap.h | 6 +- 4 files changed, 128 insertions(+), 15 deletions(-) create mode 100644 be/src/common/exception.cpp create mode 100644 be/src/common/exception.h diff --git a/be/src/common/exception.cpp b/be/src/common/exception.cpp new file mode 100644 index 00000000000000..ebc79631d18507 --- /dev/null +++ b/be/src/common/exception.cpp @@ -0,0 +1,48 @@ +// 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. + +#pragma once + +#include "common/exception.h" + +namespace doris { + +Exception::Exception(int code, const std::string_view msg) { + _code = code; + _err_msg = std::make_unique(); + _err_msg->_msg = msg; +#ifdef ENABLE_STACKTRACE + if constexpr (capture_stacktrace()) { + _err_msg->_stack = get_stack_trace(); + } +#endif +} +Exception::Exception(int code, const std::string_view msg, const Exception& nested) { + _code = code; + _err_msg = std::make_unique(); + _err_msg->_msg = msg; +#ifdef ENABLE_STACKTRACE + if constexpr (capture_stacktrace()) { + _err_msg->_stack = get_stack_trace(); + } +#endif + _nested_excption = std::make_unique(); + _nested_excption->_code = nested._code; + _nested_excption->_err_msg = nested._err_msg; +} + +} // namespace doris \ No newline at end of file diff --git a/be/src/common/exception.h b/be/src/common/exception.h new file mode 100644 index 00000000000000..d3ccab0f980589 --- /dev/null +++ b/be/src/common/exception.h @@ -0,0 +1,76 @@ +// 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. + +#pragma once + +#include "common/status.h" + +namespace doris { + +class Exception : public std::exception { +public: + Exception() : _code(ErrorCode::OK) {} + Exception(int code, const std::string_view msg); + Exception(int code, const std::string_view msg, const Exception& nested); + + // Format message with fmt::format, like the logging functions. + template + Exception(int code, const std::string_view fmt, Args&&... args) + : Exception(code, fmt::format(fmt, std::forward(args)...)) {} + + void rethrow() const override { throw *this; } + + std::string code_as_string() const { + return (int)_code >= 0 ? doris::to_string(static_cast(_code)) + : fmt::format("E{}", (int16_t)_code); + } + + std::string to_string() const; + +private: + int _code; + struct ErrMsg { + std::string _msg; +#ifdef ENABLE_STACKTRACE + std::string _stack; +#endif + }; + std::unique_ptr _err_msg; + std::unique_ptr _nested_excption; +}; + +inline std::ostream& operator<<(std::ostream& ostr, const Exception& exp) { + ostr << '[' << exp.code_as_string() << ']'; + ostr << (exp._err_msg ? exp._err_msg->_msg : ""); +#ifdef ENABLE_STACKTRACE + if (exp._err_msg && !exp._err_msg->_stack.empty()) { + ostr << '\n' << exp._err_msg->_stack; + } +#endif + if (_nested_excption != nullptr) { + ostr << '\n' << "Caused by:" << *_nested_excption; + } + return ostr; +} + +inline std::string Exception::to_string() const { + std::stringstream ss; + ss << *this; + return ss.str(); +} + +} // namespace doris \ No newline at end of file diff --git a/be/src/vec/exprs/table_function/vexplode_bitmap.cpp b/be/src/vec/exprs/table_function/vexplode_bitmap.cpp index 4269a343396028..f680922e7c5e28 100644 --- a/be/src/vec/exprs/table_function/vexplode_bitmap.cpp +++ b/be/src/vec/exprs/table_function/vexplode_bitmap.cpp @@ -27,13 +27,6 @@ VExplodeBitmapTableFunction::VExplodeBitmapTableFunction() { _fn_name = "vexplode_bitmap"; } -VExplodeBitmapTableFunction::~VExplodeBitmapTableFunction() { - if (_cur_iter != nullptr) { - delete _cur_iter; - _cur_iter = nullptr; - } -} - Status VExplodeBitmapTableFunction::process_init(vectorized::Block* block) { CHECK(_vexpr_context->root()->children().size() == 1) << "VExplodeNumbersTableFunction must be have 1 children but have " @@ -84,11 +77,7 @@ Status VExplodeBitmapTableFunction::get_value(void** output) { void VExplodeBitmapTableFunction::_reset_iterator() { DCHECK(_cur_bitmap->cardinality() > 0) << _cur_bitmap->cardinality(); - if (_cur_iter != nullptr) { - delete _cur_iter; - _cur_iter = nullptr; - } - _cur_iter = new BitmapValueIterator(*_cur_bitmap); + _cur_iter.reset(new BitmapValueIterator(*_cur_bitmap)); _cur_value = **_cur_iter; _cur_offset = 0; } diff --git a/be/src/vec/exprs/table_function/vexplode_bitmap.h b/be/src/vec/exprs/table_function/vexplode_bitmap.h index 535fdaf64562d2..7841c233dc7391 100644 --- a/be/src/vec/exprs/table_function/vexplode_bitmap.h +++ b/be/src/vec/exprs/table_function/vexplode_bitmap.h @@ -26,7 +26,7 @@ namespace doris::vectorized { class VExplodeBitmapTableFunction final : public TableFunction { public: VExplodeBitmapTableFunction(); - ~VExplodeBitmapTableFunction() override; + ~VExplodeBitmapTableFunction() = default; Status reset() override; Status get_value(void** output) override; @@ -39,10 +39,10 @@ class VExplodeBitmapTableFunction final : public TableFunction { private: void _reset_iterator(); - + // Not own object, just a reference const BitmapValue* _cur_bitmap = nullptr; // iterator of _cur_bitmap - BitmapValueIterator* _cur_iter = nullptr; + std::unique_ptr _cur_iter = nullptr; // current value read from bitmap, it will be referenced by // table function scan node. uint64_t _cur_value = 0; From fd4e9b27372005a10255d09386459cea6cc8b11b Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 18:20:55 +0800 Subject: [PATCH 02/19] f --- be/src/common/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/be/src/common/CMakeLists.txt b/be/src/common/CMakeLists.txt index 872bf36e5c019e..1d2254c6894737 100644 --- a/be/src/common/CMakeLists.txt +++ b/be/src/common/CMakeLists.txt @@ -24,6 +24,7 @@ add_library(Common STATIC resource_tls.cpp logconfig.cpp configbase.cpp + exception.cpp ) # Generate env_config.h according to env_config.h.in From 6c8868a6f6998c2118ab586f8a75c352c22894f9 Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 18:26:26 +0800 Subject: [PATCH 03/19] f --- be/src/common/exception.cpp | 2 -- be/src/common/exception.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/be/src/common/exception.cpp b/be/src/common/exception.cpp index ebc79631d18507..a4742e68fa166c 100644 --- a/be/src/common/exception.cpp +++ b/be/src/common/exception.cpp @@ -15,8 +15,6 @@ // specific language governing permissions and limitations // under the License. -#pragma once - #include "common/exception.h" namespace doris { diff --git a/be/src/common/exception.h b/be/src/common/exception.h index d3ccab0f980589..59112349375948 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -41,6 +41,8 @@ class Exception : public std::exception { std::string to_string() const; + friend std::ostream& operator<<(std::ostream& ostr, const Exception& exp); + private: int _code; struct ErrMsg { From 1fdf0120ba3251069e9ab0a07152a0cce4f42ae8 Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 18:28:27 +0800 Subject: [PATCH 04/19] f --- be/src/common/exception.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/be/src/common/exception.h b/be/src/common/exception.h index 59112349375948..1a9a1bcc4a4861 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -32,8 +32,6 @@ class Exception : public std::exception { Exception(int code, const std::string_view fmt, Args&&... args) : Exception(code, fmt::format(fmt, std::forward(args)...)) {} - void rethrow() const override { throw *this; } - std::string code_as_string() const { return (int)_code >= 0 ? doris::to_string(static_cast(_code)) : fmt::format("E{}", (int16_t)_code); From c6650d9630b8a44db0d389b523f896e8bd6ce164 Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 18:29:29 +0800 Subject: [PATCH 05/19] f --- be/src/common/exception.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/be/src/common/exception.h b/be/src/common/exception.h index 1a9a1bcc4a4861..61b2f8e29de197 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -61,8 +61,8 @@ inline std::ostream& operator<<(std::ostream& ostr, const Exception& exp) { ostr << '\n' << exp._err_msg->_stack; } #endif - if (_nested_excption != nullptr) { - ostr << '\n' << "Caused by:" << *_nested_excption; + if (exp._nested_excption != nullptr) { + ostr << '\n' << "Caused by:" << *exp._nested_excption; } return ostr; } From 8b17d26551ad13914957a0278d17c29497310ce0 Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 18:49:43 +0800 Subject: [PATCH 06/19] f --- be/src/common/exception.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/be/src/common/exception.cpp b/be/src/common/exception.cpp index a4742e68fa166c..e22835cfed788f 100644 --- a/be/src/common/exception.cpp +++ b/be/src/common/exception.cpp @@ -24,9 +24,7 @@ Exception::Exception(int code, const std::string_view msg) { _err_msg = std::make_unique(); _err_msg->_msg = msg; #ifdef ENABLE_STACKTRACE - if constexpr (capture_stacktrace()) { - _err_msg->_stack = get_stack_trace(); - } + _err_msg->_stack = get_stack_trace(); #endif } Exception::Exception(int code, const std::string_view msg, const Exception& nested) { @@ -34,13 +32,14 @@ Exception::Exception(int code, const std::string_view msg, const Exception& nest _err_msg = std::make_unique(); _err_msg->_msg = msg; #ifdef ENABLE_STACKTRACE - if constexpr (capture_stacktrace()) { - _err_msg->_stack = get_stack_trace(); - } + _err_msg->_stack = get_stack_trace(); #endif _nested_excption = std::make_unique(); _nested_excption->_code = nested._code; - _nested_excption->_err_msg = nested._err_msg; + _nested_excption->_err_msg->_msg = nested._err_msg->_msg; +#ifdef ENABLE_STACKTRACE + _nested_excption->_err_msg->_stack = nested._err_msg->_stack; +#endif } } // namespace doris \ No newline at end of file From d479c3d0ee9264875b77189816574dcf39dbf7bc Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:09:53 +0800 Subject: [PATCH 07/19] f --- be/src/common/exception.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/be/src/common/exception.h b/be/src/common/exception.h index 61b2f8e29de197..2f1501b722312f 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -37,6 +37,8 @@ class Exception : public std::exception { : fmt::format("E{}", (int16_t)_code); } + int code() { return _code; } + std::string to_string() const; friend std::ostream& operator<<(std::ostream& ostr, const Exception& exp); From de4da11b35c5c208a6c14fea4129b8af98d53426 Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:21:31 +0800 Subject: [PATCH 08/19] f --- be/test/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/be/test/CMakeLists.txt b/be/test/CMakeLists.txt index 054cb5f74b0107..330e1cd82a2931 100644 --- a/be/test/CMakeLists.txt +++ b/be/test/CMakeLists.txt @@ -31,6 +31,7 @@ set(COMMON_TEST_FILES common/resource_tls_test.cpp common/status_test.cpp common/config_test.cpp + common/exception_test.cpp ) set(ENV_TEST_FILES env/env_posix_test.cpp From c540ee865a7fadd86eda426da6d6044332272097 Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:22:08 +0800 Subject: [PATCH 09/19] f --- be/test/common/exception_test.cpp | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 be/test/common/exception_test.cpp diff --git a/be/test/common/exception_test.cpp b/be/test/common/exception_test.cpp new file mode 100644 index 00000000000000..12dc170b39e02b --- /dev/null +++ b/be/test/common/exception_test.cpp @@ -0,0 +1,45 @@ +// 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. + +#include "common/exception.h" + +#include + +#include + +namespace doris { + +class ExceptionTest : public testing::Test {}; + +TEST_F(ExceptionTest, OK) { + // default + try { + throw doris::Exception(); + } catch (doris::Exception& e) { + EXPECT_TRUE(e.code() == ErrorCode::OK); + } +} + +TEST_F(ExceptionTest, SingleError) { + try { + throw doris::Exception(ErrorCode::OS_ERROR, "test os error {}", "bug"); + } catch (doris::Exception& e) { + std::cout << e << std::endl; + } +} + +} // namespace doris From f199bfaefec15ed97b3e11fc253ebd2612dc05df Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:26:46 +0800 Subject: [PATCH 10/19] f --- be/src/common/exception.cpp | 6 ------ be/src/common/exception.h | 4 ---- 2 files changed, 10 deletions(-) diff --git a/be/src/common/exception.cpp b/be/src/common/exception.cpp index e22835cfed788f..18b9c0b9419b71 100644 --- a/be/src/common/exception.cpp +++ b/be/src/common/exception.cpp @@ -23,23 +23,17 @@ Exception::Exception(int code, const std::string_view msg) { _code = code; _err_msg = std::make_unique(); _err_msg->_msg = msg; -#ifdef ENABLE_STACKTRACE _err_msg->_stack = get_stack_trace(); -#endif } Exception::Exception(int code, const std::string_view msg, const Exception& nested) { _code = code; _err_msg = std::make_unique(); _err_msg->_msg = msg; -#ifdef ENABLE_STACKTRACE _err_msg->_stack = get_stack_trace(); -#endif _nested_excption = std::make_unique(); _nested_excption->_code = nested._code; _nested_excption->_err_msg->_msg = nested._err_msg->_msg; -#ifdef ENABLE_STACKTRACE _nested_excption->_err_msg->_stack = nested._err_msg->_stack; -#endif } } // namespace doris \ No newline at end of file diff --git a/be/src/common/exception.h b/be/src/common/exception.h index 2f1501b722312f..c622c1f97ccedf 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -47,9 +47,7 @@ class Exception : public std::exception { int _code; struct ErrMsg { std::string _msg; -#ifdef ENABLE_STACKTRACE std::string _stack; -#endif }; std::unique_ptr _err_msg; std::unique_ptr _nested_excption; @@ -58,11 +56,9 @@ class Exception : public std::exception { inline std::ostream& operator<<(std::ostream& ostr, const Exception& exp) { ostr << '[' << exp.code_as_string() << ']'; ostr << (exp._err_msg ? exp._err_msg->_msg : ""); -#ifdef ENABLE_STACKTRACE if (exp._err_msg && !exp._err_msg->_stack.empty()) { ostr << '\n' << exp._err_msg->_stack; } -#endif if (exp._nested_excption != nullptr) { ostr << '\n' << "Caused by:" << *exp._nested_excption; } From cf406eb883584d851b32ba113cab5eee6209e979 Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:28:09 +0800 Subject: [PATCH 11/19] f --- be/src/common/exception.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/be/src/common/exception.cpp b/be/src/common/exception.cpp index 18b9c0b9419b71..7d028e3929fcdf 100644 --- a/be/src/common/exception.cpp +++ b/be/src/common/exception.cpp @@ -17,6 +17,7 @@ #include "common/exception.h" +#include "util/stack_util.h" namespace doris { Exception::Exception(int code, const std::string_view msg) { From 68ad1a66e515061d9d53aebd3416715481fcd428 Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:32:14 +0800 Subject: [PATCH 12/19] f --- be/src/common/exception.h | 2 +- be/test/common/exception_test.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/be/src/common/exception.h b/be/src/common/exception.h index c622c1f97ccedf..726f5360ba62ba 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -54,7 +54,7 @@ class Exception : public std::exception { }; inline std::ostream& operator<<(std::ostream& ostr, const Exception& exp) { - ostr << '[' << exp.code_as_string() << ']'; + ostr << '[' << exp.code_as_string() << '] '; ostr << (exp._err_msg ? exp._err_msg->_msg : ""); if (exp._err_msg && !exp._err_msg->_stack.empty()) { ostr << '\n' << exp._err_msg->_stack; diff --git a/be/test/common/exception_test.cpp b/be/test/common/exception_test.cpp index 12dc170b39e02b..ebf47aa3e935a0 100644 --- a/be/test/common/exception_test.cpp +++ b/be/test/common/exception_test.cpp @@ -36,10 +36,23 @@ TEST_F(ExceptionTest, OK) { TEST_F(ExceptionTest, SingleError) { try { - throw doris::Exception(ErrorCode::OS_ERROR, "test os error {}", "bug"); + throw doris::Exception(ErrorCode::OS_ERROR, "test OS_ERROR {}", "bug"); } catch (doris::Exception& e) { std::cout << e << std::endl; } } +TEST_F(ExceptionTest, NestedError) { + try { + throw doris::Exception(ErrorCode::OS_ERROR, "test OS_ERROR {}", "bug"); + } catch (doris::Exception& e1) { + std::cout << e << std::endl; + try { + throw doris::Exception(ErrorCode::INVALID_ARGUMENT, "test INVALID_ARGUMENT", e); + } catch (doris::Exception& e2) { + std::cout << e << std::endl; + } + } +} + } // namespace doris From f627d24e23ce5058de2021b47c89132ea3046c2f Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:33:08 +0800 Subject: [PATCH 13/19] f --- be/src/common/exception.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/src/common/exception.h b/be/src/common/exception.h index 726f5360ba62ba..6701398d01b55f 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -54,7 +54,7 @@ class Exception : public std::exception { }; inline std::ostream& operator<<(std::ostream& ostr, const Exception& exp) { - ostr << '[' << exp.code_as_string() << '] '; + ostr << '[' << exp.code_as_string() << "] "; ostr << (exp._err_msg ? exp._err_msg->_msg : ""); if (exp._err_msg && !exp._err_msg->_stack.empty()) { ostr << '\n' << exp._err_msg->_stack; From 71c883ba520abafa8303a573bdc20f0702e8796a Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:33:45 +0800 Subject: [PATCH 14/19] f --- be/test/common/exception_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/be/test/common/exception_test.cpp b/be/test/common/exception_test.cpp index ebf47aa3e935a0..bededab01ab6b0 100644 --- a/be/test/common/exception_test.cpp +++ b/be/test/common/exception_test.cpp @@ -46,11 +46,11 @@ TEST_F(ExceptionTest, NestedError) { try { throw doris::Exception(ErrorCode::OS_ERROR, "test OS_ERROR {}", "bug"); } catch (doris::Exception& e1) { - std::cout << e << std::endl; + std::cout << e1 << std::endl; try { - throw doris::Exception(ErrorCode::INVALID_ARGUMENT, "test INVALID_ARGUMENT", e); + throw doris::Exception(ErrorCode::INVALID_ARGUMENT, "test INVALID_ARGUMENT", e1); } catch (doris::Exception& e2) { - std::cout << e << std::endl; + std::cout << e2 << std::endl; } } } From 6bfa00f5f3120f936cd0f5686d1d00489d703abc Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:36:24 +0800 Subject: [PATCH 15/19] f --- be/src/common/exception.cpp | 2 +- be/src/common/exception.h | 4 +++- be/test/common/exception_test.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/be/src/common/exception.cpp b/be/src/common/exception.cpp index 7d028e3929fcdf..6b53f06dc849f5 100644 --- a/be/src/common/exception.cpp +++ b/be/src/common/exception.cpp @@ -26,7 +26,7 @@ Exception::Exception(int code, const std::string_view msg) { _err_msg->_msg = msg; _err_msg->_stack = get_stack_trace(); } -Exception::Exception(int code, const std::string_view msg, const Exception& nested) { +Exception::Exception(const Exception& nested, int code, const std::string_view msg) { _code = code; _err_msg = std::make_unique(); _err_msg->_msg = msg; diff --git a/be/src/common/exception.h b/be/src/common/exception.h index 6701398d01b55f..e96db81eb6c783 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -25,7 +25,9 @@ class Exception : public std::exception { public: Exception() : _code(ErrorCode::OK) {} Exception(int code, const std::string_view msg); - Exception(int code, const std::string_view msg, const Exception& nested); + // add nested exception as first param, or the template may could not find + // the correct method for ...args + Exception(const Exception& nested, int code, const std::string_view msg); // Format message with fmt::format, like the logging functions. template diff --git a/be/test/common/exception_test.cpp b/be/test/common/exception_test.cpp index bededab01ab6b0..17800955242bbb 100644 --- a/be/test/common/exception_test.cpp +++ b/be/test/common/exception_test.cpp @@ -48,7 +48,7 @@ TEST_F(ExceptionTest, NestedError) { } catch (doris::Exception& e1) { std::cout << e1 << std::endl; try { - throw doris::Exception(ErrorCode::INVALID_ARGUMENT, "test INVALID_ARGUMENT", e1); + throw doris::Exception(e1, ErrorCode::INVALID_ARGUMENT, "test INVALID_ARGUMENT"); } catch (doris::Exception& e2) { std::cout << e2 << std::endl; } From de58e5bc701a42cf33c6c927dd6ba19b9db903f8 Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:38:25 +0800 Subject: [PATCH 16/19] f --- be/src/common/exception.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/be/src/common/exception.cpp b/be/src/common/exception.cpp index 6b53f06dc849f5..4efc981f5e2f1a 100644 --- a/be/src/common/exception.cpp +++ b/be/src/common/exception.cpp @@ -33,6 +33,7 @@ Exception::Exception(const Exception& nested, int code, const std::string_view m _err_msg->_stack = get_stack_trace(); _nested_excption = std::make_unique(); _nested_excption->_code = nested._code; + _nested_excption->_err_msg = std::make_unique(); _nested_excption->_err_msg->_msg = nested._err_msg->_msg; _nested_excption->_err_msg->_stack = nested._err_msg->_stack; } From 625ead56797850c5d898ff83f24fca21d9f97b3d Mon Sep 17 00:00:00 2001 From: yiguolei Date: Tue, 7 Mar 2023 19:44:17 +0800 Subject: [PATCH 17/19] f --- be/test/common/exception_test.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/be/test/common/exception_test.cpp b/be/test/common/exception_test.cpp index 17800955242bbb..5610c3b5706c34 100644 --- a/be/test/common/exception_test.cpp +++ b/be/test/common/exception_test.cpp @@ -20,6 +20,7 @@ #include #include +#include namespace doris { @@ -38,7 +39,7 @@ TEST_F(ExceptionTest, SingleError) { try { throw doris::Exception(ErrorCode::OS_ERROR, "test OS_ERROR {}", "bug"); } catch (doris::Exception& e) { - std::cout << e << std::endl; + EXPECT_TRUE(e.to_string().find("OS_ERROR") != std::string::npos); } } @@ -46,11 +47,12 @@ TEST_F(ExceptionTest, NestedError) { try { throw doris::Exception(ErrorCode::OS_ERROR, "test OS_ERROR {}", "bug"); } catch (doris::Exception& e1) { - std::cout << e1 << std::endl; + EXPECT_TRUE(e1.to_string().find("OS_ERROR") != std::string::npos); try { throw doris::Exception(e1, ErrorCode::INVALID_ARGUMENT, "test INVALID_ARGUMENT"); } catch (doris::Exception& e2) { - std::cout << e2 << std::endl; + EXPECT_TRUE(e2.to_string().find("OS_ERROR") != std::string::npos); + EXPECT_TRUE(e2.to_string().find("INVALID_ARGUMENT") != std::string::npos); } } } From 30aa395b2caf4e4880874320e5f1108fb474e111 Mon Sep 17 00:00:00 2001 From: yiguolei <676222867@qq.com> Date: Tue, 7 Mar 2023 21:38:04 +0800 Subject: [PATCH 18/19] Update be/src/vec/exprs/table_function/vexplode_bitmap.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- be/src/vec/exprs/table_function/vexplode_bitmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/src/vec/exprs/table_function/vexplode_bitmap.h b/be/src/vec/exprs/table_function/vexplode_bitmap.h index 7841c233dc7391..3d4b7c2ff0b044 100644 --- a/be/src/vec/exprs/table_function/vexplode_bitmap.h +++ b/be/src/vec/exprs/table_function/vexplode_bitmap.h @@ -26,7 +26,7 @@ namespace doris::vectorized { class VExplodeBitmapTableFunction final : public TableFunction { public: VExplodeBitmapTableFunction(); - ~VExplodeBitmapTableFunction() = default; + ~VExplodeBitmapTableFunction() override = default; Status reset() override; Status get_value(void** output) override; From cd6ae41b4a5cdbe5e592359a045270ea32e78385 Mon Sep 17 00:00:00 2001 From: yiguolei <676222867@qq.com> Date: Tue, 7 Mar 2023 21:38:15 +0800 Subject: [PATCH 19/19] Update be/src/common/exception.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- be/src/common/exception.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/src/common/exception.h b/be/src/common/exception.h index e96db81eb6c783..fff3215d31a938 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -39,7 +39,7 @@ class Exception : public std::exception { : fmt::format("E{}", (int16_t)_code); } - int code() { return _code; } + int code() const { return _code; } std::string to_string() const;