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

Commit

Permalink
fix: error handling for refs/refs local (#997)
Browse files Browse the repository at this point in the history
* fix: error handling for refs/refs local

* fix: ensure errors are passed back from stream-to-value

* chore: update interface-ipfs-core
  • Loading branch information
dirkmc authored and Alan Shaw committed May 16, 2019
1 parent 84117a1 commit 391351d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
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)
)
}

module.exports = streamToValue

0 comments on commit 391351d

Please sign in to comment.