@@ -178,7 +178,7 @@ class Hypercore extends EventEmitter {
178178 noiseStream = new NoiseSecretStream ( isInitiator , null , opts )
179179 outerStream = noiseStream . rawStream
180180 }
181- if ( ! noiseStream ) throw BAD_ARGUMENT ( 'Invalid stream' )
181+ if ( ! noiseStream ) throw BAD_ARGUMENT ( 'Invalid stream' , this . discoveryKey )
182182
183183 if ( ! noiseStream . userData ) {
184184 const protocol = Protomux . from ( noiseStream )
@@ -211,10 +211,10 @@ class Hypercore extends EventEmitter {
211211 if ( this . closing ) {
212212 // This makes the closing logic a lot easier. If this turns out to be a problem
213213 // in practice, open an issue and we'll try to make a solution for it.
214- throw SESSION_CLOSED ( 'Cannot make sessions on a closing core' )
214+ throw SESSION_CLOSED ( 'Cannot make sessions on a closing core' , this . discoveryKey )
215215 }
216216 if ( opts . checkout !== undefined && ! opts . name && ! opts . atom ) {
217- throw ASSERTION ( 'Checkouts are only supported on atoms or named sessions' )
217+ throw ASSERTION ( 'Checkouts are only supported on atoms or named sessions' , this . discoveryKey )
218218 }
219219
220220 const wait = opts . wait === false ? false : this . wait
@@ -253,7 +253,7 @@ class Hypercore extends EventEmitter {
253253 }
254254
255255 if ( ! isEncryptionProvider ( encryption ) ) {
256- throw ASSERTION ( 'Provider does not satisfy HypercoreEncryption interface' )
256+ throw ASSERTION ( 'Provider does not satisfy HypercoreEncryption interface' , this . discoveryKey )
257257 }
258258
259259 this . encryption = encryption
@@ -383,10 +383,10 @@ class Hypercore extends EventEmitter {
383383 }
384384
385385 if ( this . state && checkout !== - 1 ) {
386- if ( ! opts . name && ! opts . atom ) throw ASSERTION ( 'Checkouts must be named or atomized' )
387- if ( checkout > this . state . length ) throw ASSERTION ( 'Invalid checkout ' + checkout + ' for ' + opts . name + ', length is ' + this . state . length )
386+ if ( ! opts . name && ! opts . atom ) throw ASSERTION ( 'Checkouts must be named or atomized' , this . discoveryKey )
387+ if ( checkout > this . state . length ) throw ASSERTION ( 'Invalid checkout ' + checkout + ' for ' + opts . name + ', length is ' + this . state . length , this . discoveryKey )
388388 if ( this . state . prologue && checkout < this . state . prologue . length ) {
389- throw ASSERTION ( 'Invalid checkout ' + checkout + ' for ' + opts . name + ', prologue length is ' + this . state . prologue . length )
389+ throw ASSERTION ( 'Invalid checkout ' + checkout + ' for ' + opts . name + ', prologue length is ' + this . state . prologue . length , this . discoveryKey )
390390 }
391391 if ( checkout < this . state . length ) await this . state . truncate ( checkout , this . fork )
392392 }
@@ -637,7 +637,7 @@ class Hypercore extends EventEmitter {
637637
638638 this . core = core
639639
640- old . replicator . clearRequests ( this . activeRequests , SESSION_MOVED ( ) )
640+ old . replicator . clearRequests ( this . activeRequests , SESSION_MOVED ( undefined , this . discoveryKey ) )
641641
642642 this . emit ( 'migrate' , this . key )
643643 }
@@ -697,7 +697,7 @@ class Hypercore extends EventEmitter {
697697
698698 async seek ( bytes , opts ) {
699699 if ( this . opened === false ) await this . opening
700- if ( ! isValidIndex ( bytes ) ) throw ASSERTION ( 'seek is invalid' )
700+ if ( ! isValidIndex ( bytes ) ) throw ASSERTION ( 'seek is invalid' , this . discoveryKey )
701701
702702 const activeRequests = ( opts && opts . activeRequests ) || this . activeRequests
703703
@@ -716,7 +716,7 @@ class Hypercore extends EventEmitter {
716716 const offset = await s . update ( )
717717 if ( offset ) return offset
718718
719- if ( this . closing !== null ) throw SESSION_CLOSED ( )
719+ if ( this . closing !== null ) throw SESSION_CLOSED ( undefined , this . discoveryKey )
720720
721721 if ( ! this . _shouldWait ( opts , this . wait ) ) return null
722722
@@ -735,7 +735,7 @@ class Hypercore extends EventEmitter {
735735
736736 async has ( start , end = start + 1 ) {
737737 if ( this . opened === false ) await this . opening
738- if ( ! isValidIndex ( start ) || ! isValidIndex ( end ) ) throw ASSERTION ( 'has range is invalid' )
738+ if ( ! isValidIndex ( start ) || ! isValidIndex ( end ) ) throw ASSERTION ( 'has range is invalid' , this . discoveryKey )
739739
740740 if ( this . state . isDefault ( ) ) {
741741 if ( end === start + 1 ) return this . core . bitfield . get ( start )
@@ -765,9 +765,9 @@ class Hypercore extends EventEmitter {
765765
766766 async get ( index , opts ) {
767767 if ( this . opened === false ) await this . opening
768- if ( ! isValidIndex ( index ) ) throw ASSERTION ( 'block index is invalid' )
768+ if ( ! isValidIndex ( index ) ) throw ASSERTION ( 'block index is invalid' , this . discoveryKey )
769769
770- if ( this . closing !== null ) throw SESSION_CLOSED ( )
770+ if ( this . closing !== null ) throw SESSION_CLOSED ( undefined , this . discoveryKey )
771771
772772 const encoding = ( opts && opts . valueEncoding && c . from ( opts . valueEncoding ) ) || this . valueEncoding
773773
@@ -792,14 +792,14 @@ class Hypercore extends EventEmitter {
792792
793793 async clear ( start , end = start + 1 , opts ) {
794794 if ( this . opened === false ) await this . opening
795- if ( this . closing !== null ) throw SESSION_CLOSED ( )
795+ if ( this . closing !== null ) throw SESSION_CLOSED ( undefined , this . discoveryKey )
796796
797797 if ( typeof end === 'object' ) {
798798 opts = end
799799 end = start + 1
800800 }
801801
802- if ( ! isValidIndex ( start ) || ! isValidIndex ( end ) ) throw ASSERTION ( 'clear range is invalid' )
802+ if ( ! isValidIndex ( start ) || ! isValidIndex ( end ) ) throw ASSERTION ( 'clear range is invalid' , this . discoveryKey )
803803
804804 const cleared = ( opts && opts . diff ) ? { blocks : 0 } : null
805805
@@ -821,7 +821,7 @@ class Hypercore extends EventEmitter {
821821
822822 if ( block !== null ) return block
823823
824- if ( this . closing !== null ) throw SESSION_CLOSED ( )
824+ if ( this . closing !== null ) throw SESSION_CLOSED ( undefined , this . discoveryKey )
825825
826826 // snapshot should check if core has block
827827 if ( this . _snapshot !== null ) {
@@ -911,7 +911,7 @@ class Hypercore extends EventEmitter {
911911
912912 const isDefault = this . state === this . core . state
913913 const writable = ! this . _readonly && ! ! ( signature || ( keyPair && keyPair . secretKey ) )
914- if ( isDefault && writable === false && ( newLength > 0 || fork !== this . state . fork ) ) throw SESSION_NOT_WRITABLE ( )
914+ if ( isDefault && writable === false && ( newLength > 0 || fork !== this . state . fork ) ) throw SESSION_NOT_WRITABLE ( undefined , this . discoveryKey )
915915
916916 await this . state . truncate ( newLength , fork , { keyPair, signature } )
917917
@@ -928,7 +928,7 @@ class Hypercore extends EventEmitter {
928928 const { keyPair = defaultKeyPair , signature = null , maxLength } = opts
929929 const writable = ! isDefault || ! ! signature || ! ! ( keyPair && keyPair . secretKey ) || opts . writable === true
930930
931- if ( this . _readonly || writable === false ) throw SESSION_NOT_WRITABLE ( )
931+ if ( this . _readonly || writable === false ) throw SESSION_NOT_WRITABLE ( undefined , this . discoveryKey )
932932
933933 blocks = Array . isArray ( blocks ) ? blocks : [ blocks ]
934934
@@ -943,7 +943,7 @@ class Hypercore extends EventEmitter {
943943 }
944944 for ( const b of buffers ) {
945945 if ( b . byteLength > MAX_SUGGESTED_BLOCK_SIZE ) {
946- throw BAD_ARGUMENT ( 'Appended block exceeds the maximum suggested block size' )
946+ throw BAD_ARGUMENT ( 'Appended block exceeds the maximum suggested block size' , this . discoveryKey )
947947 }
948948 }
949949
@@ -1056,7 +1056,7 @@ class Hypercore extends EventEmitter {
10561056 try {
10571057 if ( enc ) return c . decode ( enc , block )
10581058 } catch {
1059- throw DECODING_ERROR ( )
1059+ throw DECODING_ERROR ( undefined , this . discoveryKey )
10601060 }
10611061 return block
10621062 }
@@ -1097,7 +1097,7 @@ function maybeUnslab (block) {
10971097}
10981098
10991099function checkSnapshot ( snapshot , index ) {
1100- if ( index >= snapshot . state . snapshotCompatLength ) throw SNAPSHOT_NOT_AVAILABLE ( )
1100+ if ( index >= snapshot . state . snapshotCompatLength ) throw SNAPSHOT_NOT_AVAILABLE ( undefined , this . discoveryKey )
11011101}
11021102
11031103function readBlock ( rx , index ) {
0 commit comments