diff --git a/lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3FileSystem.java b/lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3FileSystem.java index 75dc531889ec..0412bff40e33 100644 --- a/lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3FileSystem.java +++ b/lib/trino-filesystem-s3/src/main/java/io/trino/filesystem/s3/S3FileSystem.java @@ -203,7 +203,14 @@ private void deleteObjects(Collection locations) try { DeleteObjectsResponse response = client.deleteObjects(request); for (S3Error error : response.errors()) { - failures.put("s3://%s/%s".formatted(bucket, error.key()), error.code()); + String filePath = "s3://%s/%s".formatted(bucket, error.key()); + if (error.message() == null) { + // If the error message is null, we just use the error code + failures.put(filePath, error.code()); + } + else { + failures.put(filePath, "%s (%s)".formatted(error.message(), error.code())); + } } } catch (SdkException e) {