Skip to content

Commit 21343ca

Browse files
committed
Handle empty s3 response
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.
1 parent 9c7fc45 commit 21343ca

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
root: true,
33
parserOptions: {
4-
ecmaVersion: 6,
4+
ecmaVersion: 'latest',
55
sourceType: 'module'
66
},
77
extends: 'eslint:recommended',

lib/s3.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ module.exports = CoreObject.extend({
166166
var revisionPrefix = joinUriSegments(prefix, options.filePattern + ":" + options.revisionKey);
167167

168168
return listObjects({ Bucket: bucket, Prefix: revisionPrefix })
169-
.then((response) => response.Contents.find((element) => element.Key === revisionPrefix));
169+
.then((response) => response.Contents?.find((element) => element.Key === revisionPrefix));
170170
},
171171

172172
fetchRevisions: function(options) {

tests/unit/lib/s3-test.js

+9
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,15 @@ describe('s3', function() {
242242
});
243243
});
244244

245+
it('succeeds when revision key search returns no values', function() {
246+
s3Client.listObjects = function(params, cb) {
247+
cb(undefined, {});
248+
};
249+
var promise = subject.upload(options);
250+
251+
return assert.isFulfilled(promise);
252+
});
253+
245254
describe("when revisionKey was already uploaded", function() {
246255
beforeEach(function() {
247256
options.revisionKey = "123";

0 commit comments

Comments
 (0)