From dfee6e57151447b428bbde859869af5e6e3c8dd9 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Thu, 23 Nov 2017 17:39:41 -0600 Subject: [PATCH 1/2] fix: propagate trailer errors correctly --- src/utils/send-files-stream.js | 2 ++ src/utils/send-request.js | 16 ++-------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/utils/send-files-stream.js b/src/utils/send-files-stream.js index 0a40c6445..dda4f8051 100644 --- a/src/utils/send-files-stream.js +++ b/src/utils/send-files-stream.js @@ -129,6 +129,8 @@ module.exports = (send, path) => { return } + response.on('error', (err) => retStream.emit('error', err)) + response.on('data', (d) => { if (d.Bytes && options.progress) { options.progress(d.Bytes) diff --git a/src/utils/send-request.js b/src/utils/send-request.js index 336e356d2..3ab2b57e9 100644 --- a/src/utils/send-request.js +++ b/src/utils/send-request.js @@ -47,12 +47,6 @@ function onRes (buffer, cb) { // Return a stream of JSON objects if (chunkedObjects && isJson) { const outputStream = pump(res, ndjson.parse()) - // TODO: This needs reworking. - // this is a chicken and egg problem - - // 1) we can't get Trailer headers unless the response ends - // 2) we can't propagate the error, because the response stream - // is closed - // (perhaps we can workaround this using pull-streams) res.on('end', () => { let err = res.trailers['x-stream-error'] if (err) { @@ -60,15 +54,9 @@ function onRes (buffer, cb) { try { err = JSON.parse(err) } catch (e) { - err = { - Code: 'n/a', - Message: err - } + err = { Message: err } } - const error = new Error(`Server responded with 500`) - error.code = err.Code - error.message = err.Message - outputStream.destroy(error) // error is not going to be propagated + outputStream.emit('error', new Error(err.Message)) } }) return cb(null, outputStream) From 38639036ebc1e112267d14001ae6c265bfb02617 Mon Sep 17 00:00:00 2001 From: Richard Schneider Date: Sat, 25 Nov 2017 10:39:14 +1300 Subject: [PATCH 2/2] test: fix CRLFs for fixture files --- appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index b3d477011..ba93339ba 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,6 +3,9 @@ environment: - nodejs_version: "6" - nodejs_version: "8" +init: + - git config --global core.autocrlf input + # cache: # - node_modules