diff --git a/re-cache/src/main/java/com/g2forge/reassert/cache/store/DirectoryCacheStore.java b/re-cache/src/main/java/com/g2forge/reassert/cache/store/DirectoryCacheStore.java index 967ea54..a4cf170 100644 --- a/re-cache/src/main/java/com/g2forge/reassert/cache/store/DirectoryCacheStore.java +++ b/re-cache/src/main/java/com/g2forge/reassert/cache/store/DirectoryCacheStore.java @@ -15,8 +15,8 @@ public class DirectoryCacheStore implements ICacheStore { @Override public Path load(Path path) { - if (!path.isAbsolute()) throw new IllegalArgumentException(); - if (!Files.isDirectory(path)) throw new IllegalArgumentException(); + if (!path.isAbsolute()) throw new IllegalArgumentException(path + " is not absolute!"); + if (!Files.isDirectory(path)) throw new IllegalArgumentException(path + " is not directory!"); return path; } @@ -38,7 +38,7 @@ public Path store(Path path, Path value) { } } } catch (IOException exception) { - throw new RuntimeIOException(exception); + throw new RuntimeIOException("Failed to store " + value + " to " + path, exception); } return path; } diff --git a/re-cache/src/main/java/com/g2forge/reassert/cache/store/FileCacheStore.java b/re-cache/src/main/java/com/g2forge/reassert/cache/store/FileCacheStore.java index 1a8f73a..32acb7c 100644 --- a/re-cache/src/main/java/com/g2forge/reassert/cache/store/FileCacheStore.java +++ b/re-cache/src/main/java/com/g2forge/reassert/cache/store/FileCacheStore.java @@ -20,12 +20,12 @@ public Path load(Path path) { @Override public Path store(Path path, Path value) { - if (!path.isAbsolute()) throw new IllegalArgumentException(); + if (!path.isAbsolute()) throw new IllegalArgumentException(String.format("\"%1$s\" is not absolute", path)); try { Files.createDirectories(path.getParent()); Files.move(value, path, StandardCopyOption.REPLACE_EXISTING); } catch (IOException exception) { - throw new RuntimeIOException(exception); + throw new RuntimeIOException("Failed to store " + value + " to " + path, exception); } return path; } diff --git a/re-cache/src/main/java/com/g2forge/reassert/cache/store/JacksonCacheStore.java b/re-cache/src/main/java/com/g2forge/reassert/cache/store/JacksonCacheStore.java index 8f129d5..13268c9 100644 --- a/re-cache/src/main/java/com/g2forge/reassert/cache/store/JacksonCacheStore.java +++ b/re-cache/src/main/java/com/g2forge/reassert/cache/store/JacksonCacheStore.java @@ -14,8 +14,7 @@ /** * A cache store for objects, which uses a jackson object mapper to serialize and deserialize them. * - * @param - * The type of the values being stored. + * @param The type of the values being stored. */ @Getter @RequiredArgsConstructor @@ -28,22 +27,22 @@ public class JacksonCacheStore implements ICacheStore { @Override public T load(Path path) { - if (!path.isAbsolute()) throw new IllegalArgumentException(); + if (!path.isAbsolute()) throw new IllegalArgumentException(String.format("\"%1$s\" is not absolute", path)); try { return getMapper().readValue(path.toFile(), type.getErasedType()); } catch (IOException e) { - throw new RuntimeIOException(e); + throw new RuntimeIOException("Failed to load " + getType() + " from " + path, e); } } @Override public T store(Path path, T value) { - if (!path.isAbsolute()) throw new IllegalArgumentException(); + if (!path.isAbsolute()) throw new IllegalArgumentException(String.format("\"%1$s\" is not absolute", path)); try { Files.createDirectories(path.getParent()); getMapper().writeValue(path.toFile(), value); } catch (IOException e) { - throw new RuntimeIOException(e); + throw new RuntimeIOException("Failed to store " + value + " to " + path, e); } return value; } diff --git a/re-cache/src/main/java/com/g2forge/reassert/cache/store/ObjectSerializationCacheStore.java b/re-cache/src/main/java/com/g2forge/reassert/cache/store/ObjectSerializationCacheStore.java index cea0cad..2a9d9d3 100644 --- a/re-cache/src/main/java/com/g2forge/reassert/cache/store/ObjectSerializationCacheStore.java +++ b/re-cache/src/main/java/com/g2forge/reassert/cache/store/ObjectSerializationCacheStore.java @@ -27,19 +27,19 @@ public class ObjectSerializationCacheStore implements ICacheStore { @Override public T load(Path path) { - if (!path.isAbsolute()) throw new IllegalArgumentException(); + if (!path.isAbsolute()) throw new IllegalArgumentException(String.format("\"%1$s\" is not absolute", path)); try (ObjectInputStream objectInputStream = new ObjectInputStream(Files.newInputStream(path))) { return type.cast(objectInputStream.readObject()); } catch (ClassNotFoundException e) { - throw new RuntimeException(e); + throw new RuntimeException("Failed to load " + getType() + " from " + path, e); } catch (IOException e) { - throw new RuntimeIOException(e); + throw new RuntimeIOException("Failed to load " + getType() + " from " + path, e); } } @Override public T store(Path path, T value) { - if (!path.isAbsolute()) throw new IllegalArgumentException(); + if (!path.isAbsolute()) throw new IllegalArgumentException(String.format("\"%1$s\" is not absolute", path)); try { Files.createDirectories(path.getParent()); try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(Files.newOutputStream(path))) { @@ -47,7 +47,7 @@ public T store(Path path, T value) { objectOutputStream.flush(); } } catch (IOException e) { - throw new RuntimeIOException(e); + throw new RuntimeIOException("Failed to store " + value + " to " + path, e); } return value; }