Skip to content

Commit

Permalink
Merge pull request #2150 from HubSpot/s3_exceptions
Browse files Browse the repository at this point in the history
sentry cleanup in s3uploader
  • Loading branch information
ssalinas authored Oct 19, 2020
2 parents 00c2ee6 + fbf121d commit 21a73af
Showing 1 changed file with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.File;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -110,17 +111,17 @@ protected void uploadSingle(int sequence, Path file) throws Exception {
hostname
);

long fileSizeBytes = Files.size(file);
LOG.info(
"{} Uploading {} to {}/{} (size {})",
logIdentifier,
file,
bucketName,
key,
fileSizeBytes
);

try {
long fileSizeBytes = Files.size(file);
LOG.info(
"{} Uploading {} to {}/{} (size {})",
logIdentifier,
file,
bucketName,
key,
fileSizeBytes
);

ObjectMetadata objectMetadata = new ObjectMetadata();

UploaderFileAttributes fileAttributes = getFileAttributes(file);
Expand Down Expand Up @@ -212,6 +213,14 @@ protected void uploadSingle(int sequence, Path file) throws Exception {
s3Client.putObject(putObjectRequest);
}
} catch (AmazonS3Exception se) {
if (se.getMessage().contains("does not exist in our records")) {
LOG.warn(
"Upload cannot succeed with S3 key that does not exit in AWS, marking {} as complete",
uploadMetadata
);
return true;
}

LOG.warn(
"{} Couldn't upload {} due to {} - {}",
logIdentifier,
Expand All @@ -221,6 +230,12 @@ protected void uploadSingle(int sequence, Path file) throws Exception {
se
);
throw se;
} catch (NoSuchFileException nsfe) {
LOG.warn(
"File {} no longer exists, marking upload as complete",
nsfe.getFile()
);
return true;
} catch (Exception e) {
LOG.warn("Exception uploading {}", file, e);
throw e;
Expand Down

0 comments on commit 21a73af

Please sign in to comment.