Skip to content

Commit 56ba45c

Browse files
committed
fix unhandled promise warning (#1006)
1 parent 504afef commit 56ba45c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

packages/client/lib/net/protocol/boundprotocol.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ export class BoundProtocol extends EventEmitter {
167167
for (const message of messages) {
168168
const name = message.name as string
169169
const camel = name[0].toLowerCase() + name.slice(1)
170-
;(this as any)[camel] = async (args: any[]) => this.request(name, args)
170+
;(this as any)[camel] = async (args: any[]) =>
171+
this.request(name, args).catch((error: Error) => {
172+
this.emit('error', error)
173+
})
171174
}
172175
}
173176
}

packages/client/lib/sync/fullsync.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ export class FullSynchronizer extends Synchronizer {
7373
* @return {Promise} Resolves with header
7474
*/
7575
async latest(peer: Peer) {
76-
const headers = await peer.eth!.getBlockHeaders({
76+
const headers = await peer.eth?.getBlockHeaders({
7777
block: peer.eth!.status.bestHash,
7878
max: 1,
7979
})
80-
return headers[0]
80+
return headers?.[0]
8181
}
8282

8383
/**
@@ -88,8 +88,9 @@ export class FullSynchronizer extends Synchronizer {
8888
async syncWithPeer(peer?: Peer): Promise<boolean> {
8989
if (!peer) return false
9090
const latest = await this.latest(peer)
91+
if (!latest) return false
9192
const height = new BN(latest.number)
92-
const first = ((this.chain.blocks as any).height as BN).addn(1)
93+
const first = this.chain.blocks.height.addn(1)
9394
const count = height.sub(first).addn(1)
9495
if (count.lten(0)) return false
9596

packages/client/test/sync/fullsync.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ tape('[FullSynchronizer]', async (t) => {
7676
const headers = [{ number: 5 }]
7777
td.when(peer.eth.getBlockHeaders({ block: 'hash', max: 1 })).thenResolve(headers)
7878
const latest = await sync.latest(peer as any)
79-
t.equals(new BN(latest.number).toNumber(), 5, 'got height')
79+
t.equals(new BN(latest!.number).toNumber(), 5, 'got height')
8080
t.end()
8181
})
8282

0 commit comments

Comments
 (0)