gemini-code-assist[bot] commented on code in PR #18547:
URL: https://github.com/apache/tvm/pull/18547#discussion_r2592274672


##########
src/meta_schedule/utils.h:
##########
@@ -334,7 +334,17 @@ struct ThreadedTraceApply {
 
     for (int i = 0; i < n_; ++i) {
       Item& item = items_[i];
-      if (!item.postproc->Apply(sch)) {
+      try {
+        if (!item.postproc->Apply(sch)) {
+          item.fail_counter++;
+          return std::nullopt;
+        }
+      } catch (const tir::ScheduleError& e) {
+        DLOG(WARNING) << "Postproc #" << i << " failed with ScheduleError: " 
<< e.what();
+        item.fail_counter++;
+        return std::nullopt;
+      } catch (const std::exception& e) {
+        DLOG(WARNING) << "Postproc #" << i << " failed with exception: " << 
e.what();
         item.fail_counter++;
         return std::nullopt;
       }

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The failure handling logic, specifically `item.fail_counter++; return 
std::nullopt;`, is duplicated across the `if` condition and both `catch` 
blocks. This repetition can be eliminated by using a flag to track success and 
handling the failure in a single place after the `try-catch` block. This 
refactoring would improve code readability and maintainability.
   
   ```c
         bool success = true;
         try {
           if (!item.postproc->Apply(sch)) {
             success = false;
           }
         } catch (const tir::ScheduleError& e) {
           DLOG(WARNING) << "Postproc #" << i << " failed with ScheduleError: " 
<< e.what();
           success = false;
         } catch (const std::exception& e) {
           DLOG(WARNING) << "Postproc #" << i << " failed with exception: " << 
e.what();
           success = false;
         }
         if (!success) {
           item.fail_counter++;
           return std::nullopt;
         }
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to