Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cpp/src/arrow/status.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "arrow/status.h"

#include <cassert>
#include <cctype>
#include <cstdlib>
#include <iostream>
#ifdef ARROW_EXTRA_ERROR_CONTEXT
Expand Down Expand Up @@ -131,8 +132,15 @@ std::string Status::ToStringWithoutContextLines() const {
if (last_new_line_position == std::string::npos) {
break;
}
// TODO: We may want to check /:\d+ /
if (message.find(":", last_new_line_position) == std::string::npos) {
// Check for the pattern ":\d+" (colon followed by digits) to identify
// context lines in the format "filename:line expr"
auto colon_position = message.find(":", last_new_line_position);
if (colon_position == std::string::npos) {
break;
}
// Verify that the colon is followed by at least one digit
if (colon_position + 1 >= message.size() ||
!std::isdigit(static_cast<unsigned char>(message[colon_position + 1]))) {
break;
}
message = message.substr(0, last_new_line_position);
Expand Down
19 changes: 19 additions & 0 deletions cpp/src/arrow/status_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,23 @@ TEST(StatusTest, ReturnIfNotOk) {
ASSERT_EQ(StripContext(st.message()), "StatusLike: 43");
}

#ifdef ARROW_EXTRA_ERROR_CONTEXT
TEST(StatusTest, ToStringWithoutContextLines) {
Status status = Status::IOError("base error");
status.AddContextLine("file1.cc", 42, "expr");
status.AddContextLine("file2.cc", 100, "expr");

ASSERT_EQ(status.ToStringWithoutContextLines(), "IOError: base error");

Status status2(StatusCode::Invalid,
"Error message\nThis line has: a colon but no digits");
status2.AddContextLine("file.cc", 20, "expr");

std::string result = status2.ToStringWithoutContextLines();
ASSERT_EQ(result.find("file.cc:20"), std::string::npos);
ASSERT_NE(result.find("This line has: a colon but no digits"), std::string::npos);
ASSERT_NE(result.find("Error message"), std::string::npos);
}
#endif

} // namespace arrow
Loading