Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Fix error handling for refs/refs local #997

Merged
merged 3 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"dirty-chai": "^2.0.1",
"eslint-plugin-react": "^7.11.1",
"go-ipfs-dep": "0.4.19",
"interface-ipfs-core": "~0.101.0",
"interface-ipfs-core": "~0.101.1",
"ipfsd-ctl": "~0.42.0",
"nock": "^10.0.2",
"stream-equal": "^1.1.1"
Expand Down
2 changes: 2 additions & 0 deletions src/files-regular/refs-local-readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module.exports = (send) => {
send({ path: 'refs/local', qs: opts }, (err, stream) => {
if (err) { return pt.destroy(err) }

stream.once('error', (err) => pt.destroy(err))

pump(stream, through.obj(function (r, enc, cb) {
cb(null, { ref: r.Ref, err: r.Err })
}), pt)
Expand Down
2 changes: 2 additions & 0 deletions src/files-regular/refs-readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module.exports = (send) => {
send({ path: 'refs', args, qs: opts }, (err, stream) => {
if (err) { return pt.destroy(err) }

stream.once('error', (err) => pt.destroy(err))

pump(stream, through.obj(function (r, enc, cb) {
cb(null, { ref: r.Ref, err: r.Err })
}), pt)
Expand Down
10 changes: 4 additions & 6 deletions src/utils/stream-to-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ const concat = require('concat-stream')
Concatenate a stream to a single value.
*/
function streamToValue (response, callback) {
let data
pump(
response,
concat((data) => callback(null, data)),
(err) => {
if (err) {
callback(err)
}
})
concat((d) => { data = d }),
(err) => callback(err, data)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

}

module.exports = streamToValue