Skip to content

Commit

Permalink
Throw UncheckedIOException on directory creation errors
Browse files Browse the repository at this point in the history
Previously, Config#mkdir and #mkAppDir threw ConfigException if any
underlying IOException was thrown from Files#createDirectory or
Files#createDirectories respectively. This resulted in only a simple
error message being reported at the command line and the details of the
underlying exception's stack trace were lost. This change wraps and
rethrows the underlying IOException as an UncheckedIOException such that
it gets caught by the catch(Throwable) clause in BisqExecutable, which
does print a stacktrace to stderr. This is the way it always should have
worked; throwing ConfigException in these cases was an oversight in the
original implementation. This change also removes the ConfigException
constructor that allows for passing a nested exception to be wrapped as
there is actually no use case for this now that these two anomalies have
been corrected.

This change was made in the process of attempting to reproduce bisq-network#3998.
  • Loading branch information
cbeams committed Feb 24, 2020
1 parent adafd40 commit de537f0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions common/src/main/java/bisq/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ private static File mkAppDataDir(File appDataDir) {
try {
Files.createDirectories(path);
} catch (IOException ex) {
throw new ConfigException(ex, "Application data directory '%s' could not be created", path);
throw new UncheckedIOException(format("Application data directory '%s' could not be created", path), ex);
}
return appDataDir;
}
Expand All @@ -819,7 +819,7 @@ private static File mkdir(File parent, String child) {
try {
Files.createDirectory(path);
} catch (IOException ex) {
throw new ConfigException(ex, "Directory '%s' could not be created", path);
throw new UncheckedIOException(format("Directory '%s' could not be created", path), ex);
}
}
return dir;
Expand Down
4 changes: 0 additions & 4 deletions common/src/main/java/bisq/common/config/ConfigException.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ public class ConfigException extends BisqException {
public ConfigException(String format, Object... args) {
super(format, args);
}

public ConfigException(Throwable cause, String format, Object... args) {
super(cause, format, args);
}
}
5 changes: 3 additions & 2 deletions common/src/test/java/bisq/common/config/ConfigTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;

import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -228,10 +229,10 @@ public void whenConfigIsConstructed_thenAppDataDirAndSubdirsAreCreated() {
}

@Test
public void whenAppDataDirCannotBeCreated_thenConfigExceptionIsThrown() throws IOException {
public void whenAppDataDirCannotBeCreated_thenUncheckedIoExceptionIsThrown() throws IOException {
// set a userDataDir that is actually a file so appDataDir cannot be created
File aFile = Files.createTempFile("A", "File").toFile();
exceptionRule.expect(ConfigException.class);
exceptionRule.expect(UncheckedIOException.class);
exceptionRule.expectMessage(containsString("Application data directory"));
exceptionRule.expectMessage(containsString("could not be created"));
configWithOpts(opt(USER_DATA_DIR, aFile));
Expand Down

0 comments on commit de537f0

Please sign in to comment.