Skip to content

Commit dbbdcba

Browse files
author
Rishi Barad
authored
fix filename enoent error, handle readstream errors, and improve log readability (#541)
1 parent 4e590bd commit dbbdcba

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/lib/beanstalkUtils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,27 @@ export class BeanstalkUtils {
126126
objectKey: string
127127
): Promise<void> {
128128
console.log(tl.loc('UploadingBundle', applicationBundlePath, objectKey, bucketName))
129-
const fileBuffer = fs.createReadStream(applicationBundlePath)
129+
130+
// todo: remove duplicated S3 Upload logic across tasks
130131
try {
131-
const response: S3.ManagedUpload.SendData = await s3Client
132+
const readStream = fs.createReadStream(applicationBundlePath)
133+
134+
readStream.on('error', err => {
135+
if (err) {
136+
throw err
137+
}
138+
})
139+
140+
await s3Client
132141
.upload({
133142
Bucket: bucketName,
134143
Key: objectKey,
135-
Body: fileBuffer
144+
Body: readStream
136145
})
137146
.promise()
138147
console.log(tl.loc('BundleUploadCompleted'))
139148
} catch (err) {
140-
console.error(tl.loc('BundleUploadFailed', (err as Error).message), err)
149+
console.error(tl.loc('BundleUploadFailed', err))
141150
throw err
142151
}
143152
}

tests/taskTests/common/beanstalkutils-test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ describe('BeanstalkUtils', () => {
118118
expect.assertions(1)
119119
const s3 = new S3() as any
120120
s3.upload = jest.fn(() => {
121-
throw Error('it failed')
121+
throw Error('Intentional beanstalkutils-test Error')
122122
})
123-
await BeanstalkUtils.uploadBundle(s3, 'path', 'name', 'object').catch(err => {
124-
expect(`${err}`).toContain('it failed')
123+
await BeanstalkUtils.uploadBundle(s3, __filename, 'name', 'object').catch(err => {
124+
expect(`${err}`).toContain('Intentional beanstalkutils-test Error')
125125
})
126126
})
127127

@@ -131,11 +131,11 @@ describe('BeanstalkUtils', () => {
131131
s3.upload = jest.fn(args => {
132132
expect(args.Bucket).toEqual('name')
133133
expect(args.Key).toEqual('object')
134-
expect(args.Body.path).toEqual(path.join(__dirname, __filename))
134+
expect(args.Body.path).toEqual(__filename)
135135

136136
return s3BucketResponse
137137
})
138-
await BeanstalkUtils.uploadBundle(s3, path.join(__dirname, __filename), 'name', 'object')
138+
await BeanstalkUtils.uploadBundle(s3, __filename, 'name', 'object')
139139
})
140140

141141
test('VerifyApplicationExists throws on failure', async () => {

0 commit comments

Comments
 (0)