Skip to content

Commit

Permalink
improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Xin Zheng committed Oct 30, 2024
1 parent 3b26792 commit 80f4e9f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ ModuleConfiguration config = with()
JsonObject json = config.asJsonObject();
```

Properties not overridden will not be changed. Thus remaining default.x-lock-mode
Properties not overridden will not be changed. Thus remaining default.

To use default values only, the _ModuleConfiguration_ constructor without parameters can be used:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,15 @@ private void doRead(Buffer writeBuff, int offset, ByteBuffer buff, long position
try {
Integer bytesRead = ch.read(buff);
future.complete(bytesRead);
} catch (Exception e) {
log.error("", e);
} catch (IOException e) {
log.error("Failed to read data from buffer.", e);
future.fail(e);
}

}, res -> {

if (res.failed()) {
log.error("Failed to read data from buffer.", res.cause());
context.runOnContext((v) -> handler.handle(Future.failedFuture(res.cause())));
} else {
// Do the completed check
Expand Down Expand Up @@ -232,7 +233,6 @@ private void handleException(Throwable t) {
exceptionHandler.handle(t);
} else {
log.error("Unhandled exception", t);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import io.vertx.core.Promise;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.streams.WriteStream;
import org.slf4j.Logger;

import java.io.OutputStream;
import java.io.IOException;

import static org.slf4j.LoggerFactory.getLogger;

public class FileWriteStream implements WriteStream<Buffer> {
private static final Logger log = getLogger(FileWriteStream.class);
private final OutputStream outputStream;
private Handler<Throwable> exceptionHandler;
private Handler<Void> drainHandler;
Expand All @@ -37,6 +41,7 @@ public void write(Buffer buffer, Handler<AsyncResult<Void>> handler) {
if (exceptionHandler != null) {
exceptionHandler.handle(e);
}
log.error("Error writing to stream", e);
handler.handle(Future.failedFuture(e));
}
}
Expand All @@ -52,6 +57,7 @@ public Future<Void> write(Buffer buffer) {
if (exceptionHandler != null) {
exceptionHandler.handle(e);
}
log.error("Error writing to stream", e);
promise.fail(e);
}
return promise.future();
Expand All @@ -67,6 +73,7 @@ public void end(Handler<AsyncResult<Void>> handler) {
if (exceptionHandler != null) {
exceptionHandler.handle(e);
}
log.error("Error when try to end stream", e);
handler.handle(Future.failedFuture(e));
}
}
Expand All @@ -82,6 +89,7 @@ public Future<Void> end() {
if (exceptionHandler != null) {
exceptionHandler.handle(e);
}
log.error("Error when try to end stream", e);
promise.fail(e);
}
return promise.future();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.net.URI;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.DirectoryStream;
Expand Down Expand Up @@ -84,7 +85,7 @@ public S3FileSystemStorage(Vertx vertx, RestStorageExceptionFactory exceptionFac
try (var pathStream = Files.walk(root)) {
pathStream.forEach(System.out::println);
} catch (IOException e) {
throw new RuntimeException(e);
throw new UncheckedIOException(e);
}

this.fileSystemDirLister = new S3FileSystemDirLister(vertx, root.toString());
Expand Down

0 comments on commit 80f4e9f

Please sign in to comment.