Skip to content

Commit

Permalink
Simple error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Jurgen Voorneveld committed Oct 29, 2024
1 parent db128e7 commit eeb8914
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/redis/embedded/RedisInstance.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package redis.embedded;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.AccessDeniedException;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
Expand Down Expand Up @@ -35,10 +37,16 @@ protected RedisInstance(final int port, final List<String> args, final Pattern r

public synchronized void start() throws IOException {
if (active) return;
final File executable = new File(args.get(0));

if (!executable.isFile())
throw new FileNotFoundException("Redis binary " + args.get(0) + " could not be found");
if (!executable.canExecute())
throw new AccessDeniedException("Redis binary " + args.get(0) + " is not executable");

try {
process = new ProcessBuilder(args)
.directory(new File(args.get(0)).getParentFile())
.directory(executable.getParentFile())
.start();
addShutdownHook("RedisInstanceCleaner", checkedToRuntime(this::stop));
awaitServerReady(process, readyPattern, soutListener, serrListener);
Expand Down

0 comments on commit eeb8914

Please sign in to comment.