Skip to content

Commit

Permalink
add stacktrace in messages on severe error
Browse files Browse the repository at this point in the history
  • Loading branch information
kuron99 committed Nov 7, 2024
1 parent 08e0eab commit 4c2d1ee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/jogasaki/error/error_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,21 @@ 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),
source_file_path_(filepath),
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;
Expand Down
3 changes: 2 additions & 1 deletion src/jogasaki/error/error_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
9 changes: 8 additions & 1 deletion src/jogasaki/error/error_info_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ std::shared_ptr<error_info> create_error_info_with_stack_impl(
status st,
std::string_view stacktrace
) {
auto info = std::make_shared<error_info>(code, message, filepath, position, stacktrace);
auto info = std::make_shared<error_info>(
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ operation_status error_abort_impl(
filepath,
position,
res,
true
false
);
break;
case status::err_insufficient_field_storage:
Expand Down

0 comments on commit 4c2d1ee

Please sign in to comment.