Skip to content

Commit

Permalink
Fix Use fully qualified S3 uris in error message (#4923)
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Syme <[email protected]>
  • Loading branch information
robsyme authored Apr 17, 2024
1 parent 9632366 commit f1cffd1
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public InputStream newInputStream(Path path, OpenOption... options)
S3Path s3Path = (S3Path) path;

Preconditions.checkArgument(!s3Path.getKey().equals(""),
"cannot create InputStream for root directory: %s", s3Path);
"cannot create InputStream for root directory: %s", FilesEx.toUriString(s3Path));

InputStream result;
try {
Expand All @@ -213,13 +213,13 @@ public InputStream newInputStream(Path path, OpenOption... options)
.getObjectContent();

if (result == null)
throw new IOException(String.format("The specified path is a directory: %s", path));
throw new IOException(String.format("The specified path is a directory: %s", FilesEx.toUriString(s3Path)));
}
catch (AmazonS3Exception e) {
if (e.getStatusCode() == 404)
throw new NoSuchFileException(path.toString());
// otherwise throws a generic IO exception
throw new IOException(String.format("Cannot access file: %s", path),e);
throw new IOException(String.format("Cannot access file: %s", FilesEx.toUriString(s3Path)),e);
}

return result;
Expand Down Expand Up @@ -258,11 +258,11 @@ public OutputStream newOutputStream(final Path path, final OpenOption... options
if (!(create && truncateExisting)) {
if (exists(s3Path)) {
if (createNew || !truncateExisting) {
throw new FileAlreadyExistsException(path.toString());
throw new FileAlreadyExistsException(FilesEx.toUriString(s3Path));
}
} else {
if (!createNew && !create) {
throw new NoSuchFileException(path.toString());
throw new NoSuchFileException(FilesEx.toUriString(s3Path));
}
}
}
Expand Down Expand Up @@ -496,13 +496,13 @@ public void delete(Path path) throws IOException {
S3Path s3Path = (S3Path) path;

if (Files.notExists(path)){
throw new NoSuchFileException("the path: " + path + " does not exist");
throw new NoSuchFileException("the path: " + FilesEx.toUriString(s3Path) + " does not exist");
}

if (Files.isDirectory(path)){
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)){
if (stream.iterator().hasNext()){
throw new DirectoryNotEmptyException("the path: " + path + " is a directory and is not empty");
throw new DirectoryNotEmptyException("the path: " + FilesEx.toUriString(s3Path) + " is a directory and is not empty");
}
}
}
Expand Down Expand Up @@ -541,7 +541,7 @@ public void copy(Path source, Path target, CopyOption... options)
if (!actualOptions.contains(StandardCopyOption.REPLACE_EXISTING)) {
if (exists(s3Target)) {
throw new FileAlreadyExistsException(format(
"target already exists: %s", target));
"target already exists: %s", FilesEx.toUriString(s3Target)));
}
}

Expand Down

0 comments on commit f1cffd1

Please sign in to comment.