frankgh commented on code in PR #122:
URL: https://github.com/apache/cassandra-sidecar/pull/122#discussion_r1602292809
##########
src/main/java/org/apache/cassandra/sidecar/restore/RestoreJobManager.java:
##########
@@ -206,10 +221,9 @@ private Future<Void> deleteDataAsync(Path root)
{
pathStream
.sorted(Comparator.reverseOrder())
- .map(Path::toFile)
- .forEach(File::delete);
+ .forEach(path -> ThrowableUtils.propogate(() ->
Files.delete(path)));
}
- catch (IOException ioe) // thrown from Files.walk.
+ catch (Exception ioe)
Review Comment:
```suggestion
catch (Exception exception)
```
##########
src/main/java/org/apache/cassandra/sidecar/exceptions/ThrowableUtils.java:
##########
@@ -18,23 +18,49 @@
package org.apache.cassandra.sidecar.exceptions;
+import java.util.concurrent.Callable;
import java.util.function.Predicate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.cassandra.sidecar.common.server.ThrowingRunnable;
/**
* Collection of utility methods for understanding {@link Throwable} thrown
better
*/
public class ThrowableUtils
{
- private static final Logger LOGGER =
LoggerFactory.getLogger(ThrowableUtils.class);
-
private ThrowableUtils()
{
throw new UnsupportedOperationException();
}
+ /**
+ * Run the {@code actionMayThrow} and wrap any {@link Exception} thrown in
{@link RuntimeException}
+ * @param actionMayThrow action that may throw exceptions
+ * @param <R> return value type of the action
+ */
+ public static <R> R propogate(Callable<R> actionMayThrow)
+ {
+ try
+ {
+ return actionMayThrow.call();
+ }
+ catch (Exception cause)
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+
+ /**
+ * Similar to {@link #propogate(Callable)}, but takes runnable-ish
+ */
+ public static void propogate(ThrowingRunnable actionMayThrow)
Review Comment:
```suggestion
public static void propagate(ThrowingRunnable actionMayThrow)
```
##########
src/main/java/org/apache/cassandra/sidecar/exceptions/ThrowableUtils.java:
##########
@@ -18,23 +18,49 @@
package org.apache.cassandra.sidecar.exceptions;
+import java.util.concurrent.Callable;
import java.util.function.Predicate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.cassandra.sidecar.common.server.ThrowingRunnable;
/**
* Collection of utility methods for understanding {@link Throwable} thrown
better
*/
public class ThrowableUtils
{
- private static final Logger LOGGER =
LoggerFactory.getLogger(ThrowableUtils.class);
-
private ThrowableUtils()
{
throw new UnsupportedOperationException();
}
+ /**
+ * Run the {@code actionMayThrow} and wrap any {@link Exception} thrown in
{@link RuntimeException}
+ * @param actionMayThrow action that may throw exceptions
+ * @param <R> return value type of the action
+ */
+ public static <R> R propogate(Callable<R> actionMayThrow)
Review Comment:
```suggestion
public static <R> R propagate(Callable<R> actionMayThrow)
```
--
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]