Skip to content

Commit

Permalink
Catch exceptions thrown when decoding (#126)
Browse files Browse the repository at this point in the history
* Catch exceptions thrown when decoding

Peers with older incompatible hyperdb versions will cause
uncaught exceptions when they connect via the swarm.

* Quick fix -- forgot something

* Another catch
  • Loading branch information
jimpick authored and mafintosh committed May 24, 2018
1 parent 39cbf96 commit eb5228a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,11 +768,19 @@ Writer.prototype._maybeUpdateFeeds = function () {
}

Writer.prototype._decode = function (seq, buf, cb) {
var val = messages.Entry.decode(buf)
try {
var val = messages.Entry.decode(buf)
} catch (e) {
return cb(e)
}
val[util.inspect.custom] = inspect
val.seq = seq
val.path = hash(val.key, true)
val.value = val.value && this._db._valueEncoding.decode(val.value)
try {
val.value = val.value && this._db._valueEncoding.decode(val.value)
} catch (e) {
return cb(e)
}

if (this._feedsMessage && this._feedsLoaded === val.inflate) {
this._maybeUpdateFeeds()
Expand Down Expand Up @@ -834,7 +842,12 @@ Writer.prototype._loadFeeds = function (head, buf, cb) {

function onfeeds (err, buf) {
if (err) return cb(err)
done(messages.InflatedEntry.decode(buf))
try {
var msg = messages.InflatedEntry.decode(buf)
} catch (e) {
return cb(e)
}
done(msg)
}

function done (msg) {
Expand Down

0 comments on commit eb5228a

Please sign in to comment.