Skip to content

Commit

Permalink
Merge pull request #814 from Vlatombe/delete-diagnostics
Browse files Browse the repository at this point in the history
Improve exception readability in case a directory can't be deleted because it still contains files
  • Loading branch information
jglick authored Aug 13, 2024
2 parents c507410 + 3b56598 commit cff7ad4
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang.StringUtils;

/**
* Allocates temporary directories and cleans it up at the end.
Expand Down Expand Up @@ -140,9 +141,11 @@ private void delete(Path p) throws IOException {
}
Files.deleteIfExists(p);
} catch (DirectoryNotEmptyException x) {
String pathString = p.toString();
try (Stream<Path> children = Files.list(p)) {
throw new IOException(children.map(Path::toString).collect(Collectors.joining(" ")), x);
x.addSuppressed(new IOException("These files still exist : " + children.map(Path::toString).map(s -> StringUtils.removeStart(s, pathString + File.separator)).collect(Collectors.joining(", "))));
}
throw x;
}
}

Expand Down

0 comments on commit cff7ad4

Please sign in to comment.