You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "HyukjinKwon (via GitHub)" <gi...@apache.org> on 2025/12/29 10:16:05 UTC

[PR] GH-48673: [C++] Fix ToStringWithoutContextLines to check for :\d+ pattern before removing lines [arrow]

HyukjinKwon opened a new pull request, #48674:
URL: https://github.com/apache/arrow/pull/48674

   ### Rationale for this change
   
   This PR proposes to fix the todo https://github.com/apache/arrow/blob/7ebc88c8fae62ed97bc30865c845c8061132af7e/cpp/src/arrow/status.cc#L131-L134 which would allows a better parsing for line numbers.
   
   I could not find the relevant example to demonstrate within this project but assume that we have a test such as:
   
   ```cpp
   TEST(BlockParser, ErrorMessageWithColonsPreserved) {
     Status st(StatusCode::Invalid,
               "CSV parse error: Row #2: Expected 2 columns, got 3: 12:34:56,key:value,data\n"
               "Error details: Time format: 12:34:56, Key: value\n"
               "parser_test.cc:940  Parse(parser, csv, &out_size)");
   
     std::string expected_msg =
         "Invalid: CSV parse error: Row #2: Expected 2 columns, got 3: 12:34:56,key:value,data\n"
         "Error details: Time format: 12:34:56, Key: value";
   
     ASSERT_RAISES_WITH_MESSAGE(Invalid, expected_msg, st);
   }
   
   // Test with URL-like data (another common case with colons)
   TEST(BlockParser, ErrorMessageWithURLPreserved) {
     Status st(StatusCode::Invalid,
               "CSV parse error: Row #2: Expected 1 columns, got 2: http://arrow.apache.org:8080/api,data\n"
               "URL: http://arrow.apache.org:8080/api\n"
               "parser_test.cc:974  Parse(parser, csv, &out_size)");
   
     std::string expected_msg =
         "Invalid: CSV parse error: Row #2: Expected 1 columns, got 2: http://arrow.apache.org:8080/api,data\n"
         "URL: http://arrow.apache.org:8080/api";
   
     ASSERT_RAISES_WITH_MESSAGE(Invalid, expected_msg, st);
   }
   ```
   
   then it fails.
   
   ### What changes are included in this PR?
   
   Fixed `Status::ToStringWithoutContextLines()` to only remove context lines matching the `filename:line` pattern (`:\d+`), preventing legitimate error messages containing colons from being incorrectly stripped.
   
   ### Are these changes tested?
   
   Manually tested, and unittests were added, with `cmake .. --preset ninja-debug -DARROW_EXTRA_ERROR_CONTEXT=ON`.
   
   ### Are there any user-facing changes?
   
   No, test-only.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-48673: [C++] Fix ToStringWithoutContextLines to check for :\d+ pattern before removing lines [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #48674:
URL: https://github.com/apache/arrow/pull/48674#discussion_r2659953513


##########
cpp/src/arrow/status_test.cc:
##########
@@ -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);

Review Comment:
   Could you check the exact expected message instead for easy to debug failure message? If we use `find()` and `std::string::npos`, we can't show the actual message in the failure log.
   
   ```suggestion
     ASSERT_EQ(status2.ToStringWithoutContextLines(),
               "Error message\nThis line has: a colon but no digits");
   ```



##########
cpp/src/arrow/status.cc:
##########
@@ -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]))) {

Review Comment:
   Can we also check the `+ ` part in `/:\d+ /`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-48673: [C++] Fix ToStringWithoutContextLines to check for :\d+ pattern before removing lines [arrow]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #48674:
URL: https://github.com/apache/arrow/pull/48674#discussion_r2660006349


##########
cpp/src/arrow/status.cc:
##########
@@ -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]))) {

Review Comment:
   Sure!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-48673: [C++] Fix ToStringWithoutContextLines to check for :\d+ pattern before removing lines [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48674:
URL: https://github.com/apache/arrow/pull/48674#issuecomment-3696078243

   :warning: GitHub issue #48673 **has been automatically assigned in GitHub** to PR creator.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-48673: [C++] Fix ToStringWithoutContextLines to check for :\d+ pattern before removing lines [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #48674:
URL: https://github.com/apache/arrow/pull/48674


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-48673: [C++] Fix ToStringWithoutContextLines to check for :\d+ pattern before removing lines [arrow]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #48674:
URL: https://github.com/apache/arrow/pull/48674#issuecomment-3816347321

   @kou I am totally fine if you think this isn't quite worthwhile. I am more into removing those todos .. I can convert this PR to just remove that todo.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org