From 4c2d1eef81df901c7540fc518d6207f1d4d6abfd Mon Sep 17 00:00:00 2001 From: Ryoji Kurosawa Date: Thu, 7 Nov 2024 18:05:38 +0900 Subject: [PATCH] add stacktrace in messages on severe error https://github.com/project-tsurugi/tsurugi-issues/issues/247 https://github.com/project-tsurugi/tsurugi-issues/issues/1017 --- src/jogasaki/error/error_info.cpp | 10 ++++++++-- src/jogasaki/error/error_info.h | 3 ++- src/jogasaki/error/error_info_factory.cpp | 9 ++++++++- .../executor/process/impl/ops/details/error_abort.h | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/jogasaki/error/error_info.cpp b/src/jogasaki/error/error_info.cpp index a51da2596..dae88a95c 100644 --- a/src/jogasaki/error/error_info.cpp +++ b/src/jogasaki/error/error_info.cpp @@ -33,7 +33,8 @@ error_info::error_info( std::string_view message, std::string_view filepath, std::string_view position, - std::string_view stacks + std::string_view stacks, + bool include_supplemental_text_in_message ) noexcept : error_code_(code), message_(message), @@ -41,7 +42,12 @@ error_info::error_info( source_file_position_(position), stacks_(stacks), supplemental_text_(create_supplemental_text()) -{} +{ + if(include_supplemental_text_in_message) { + message_ = message_ + " " + supplemental_text_; + supplemental_text_ = {}; + } +} std::string error_info::create_supplemental_text() noexcept { using json = nlohmann::json; diff --git a/src/jogasaki/error/error_info.h b/src/jogasaki/error/error_info.h index de13e4d5c..aaa94eeaa 100644 --- a/src/jogasaki/error/error_info.h +++ b/src/jogasaki/error/error_info.h @@ -53,7 +53,8 @@ class error_info { std::string_view message, std::string_view filepath, std::string_view position, - std::string_view stacks + std::string_view stacks, + bool include_supplemental_text_in_message = false ) noexcept; /** diff --git a/src/jogasaki/error/error_info_factory.cpp b/src/jogasaki/error/error_info_factory.cpp index 53bb6427d..b0b0b19ca 100644 --- a/src/jogasaki/error/error_info_factory.cpp +++ b/src/jogasaki/error/error_info_factory.cpp @@ -37,7 +37,14 @@ std::shared_ptr create_error_info_with_stack_impl( status st, std::string_view stacktrace ) { - auto info = std::make_shared(code, message, filepath, position, stacktrace); + auto info = std::make_shared( + code, + message, + filepath, + position, + stacktrace, + ! stacktrace.empty() // if stacktrace is provided, it's severe error and message should contain it + ); info->status(st); VLOG_LP(log_trace) << "error_info:" << *info; return info; diff --git a/src/jogasaki/executor/process/impl/ops/details/error_abort.h b/src/jogasaki/executor/process/impl/ops/details/error_abort.h index 3da72f176..9e67be644 100644 --- a/src/jogasaki/executor/process/impl/ops/details/error_abort.h +++ b/src/jogasaki/executor/process/impl/ops/details/error_abort.h @@ -93,7 +93,7 @@ operation_status error_abort_impl( filepath, position, res, - true + false ); break; case status::err_insufficient_field_storage: