Skip to content

Commit

Permalink
Handle empty s3 response
Browse files Browse the repository at this point in the history
After the update to AWS SDK v3 when searching for a revision the
Contents on the response is not present if the revision hasn't been
created yet. This seemed like the smallest change to fix the problem,
and optional chaining is supported in Node 14, but I had to bump up the
ecmaVersion in the eslint config to allow it.
  • Loading branch information
jrjohnson committed Apr 5, 2024
1 parent 9c7fc45 commit 21343ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 6,
ecmaVersion: 'latest',
sourceType: 'module'
},
extends: 'eslint:recommended',
Expand Down
2 changes: 1 addition & 1 deletion lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ module.exports = CoreObject.extend({
var revisionPrefix = joinUriSegments(prefix, options.filePattern + ":" + options.revisionKey);

return listObjects({ Bucket: bucket, Prefix: revisionPrefix })
.then((response) => response.Contents.find((element) => element.Key === revisionPrefix));
.then((response) => response.Contents?.find((element) => element.Key === revisionPrefix));
},

fetchRevisions: function(options) {
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/lib/s3-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ describe('s3', function() {
});
});

it('succeeds when revision key search returns no values', function() {
s3Client.listObjects = function(params, cb) {
cb(undefined, {});
};
var promise = subject.upload(options);

return assert.isFulfilled(promise);
});

describe("when revisionKey was already uploaded", function() {
beforeEach(function() {
options.revisionKey = "123";
Expand Down

0 comments on commit 21343ca

Please sign in to comment.