davintjong-db commented on code in PR #48483:
URL: https://github.com/apache/spark/pull/48483#discussion_r1815354345


##########
common/utils/src/main/scala/org/apache/spark/util/SparkErrorUtils.scala:
##########
@@ -48,6 +48,22 @@ private[spark] trait SparkErrorUtils extends Logging {
     try f.apply(resource) finally resource.close()
   }
 
+  /**
+   * Try to initialize a resource. If an exception is throw during 
initialization, closes the
+   * resource before propagating the error. Otherwise, the caller is 
responsible for closing
+   * the resource. This means that [[T]] should provide some way to close the 
resource.
+   */
+  def tryInitializeResource[R <: Closeable, T](createResource: => 
R)(initialize: R => T): T = {
+    val resource = createResource

Review Comment:
   If an exception is thrown here:
   ```
   val intermediateReader = ... constructor ... <- here
   intermediateReader.initialize(...)
   return WrapperIterator(intermediateReader)
   ```
   It should be the responsibility of the constructor to close any resources it 
has opened if it fails, and the current code is not responsible for any open 
resources itself. So all we need to do in this case is propagate this error to 
the caller, which happens anyway.



-- 
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