diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/DebugDataDumper.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/DebugDataDumper.java index f0cd3fa4dba..56cc7310897 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/DebugDataDumper.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/DebugDataDumper.java @@ -132,11 +132,7 @@ protected boolean saveBytesToFile( try { Files.write(path, bytes.toArray()); } catch (NoSuchFileException e) { - if (!path.getParent().toFile().mkdirs()) { - LOG.error("Failed to save {} bytes to file.", description, e); - return false; - } - return saveAfterCreatingTopicDirectory(description, relativeFilePath, bytes); + return saveAfterCreatingTopicDirectory(description, path, relativeFilePath, bytes); } catch (IOException e) { LOG.error("Failed to save {} bytes to file.", description, e); return false; @@ -145,8 +141,14 @@ protected boolean saveBytesToFile( } private boolean saveAfterCreatingTopicDirectory( - final String description, final Path relativeFilePath, final Bytes bytes) { - final Path path = directory.resolve(relativeFilePath); + final String description, final Path path, final Path relativeFilePath, final Bytes bytes) { + if (!path.getParent().toFile().mkdirs()) { + LOG.error( + "Failed to save {} bytes to file. No such directory {} to save file.", + description, + relativeFilePath.getParent()); + return false; + } try { Files.write(path, bytes.toArray()); } catch (IOException e) {