Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Fix block fetch error if block not found #1082

Merged
merged 5 commits into from
Sep 24, 2018
Merged

Conversation

fabioberger
Copy link
Contributor

Description

Currently web3Wrapper.getBlockAsync throws:

TypeError: Cannot read property 'difficulty' of null

If the request for a particular block fails. A block request could fail if a node isn't fully synced, or if it's become uncle'd, among other reasons. The Ethereum JSON RPC spec specified returning null for requests where the block cannot be found.

This PR therefore renames getBlockAsync to getBlockIfExistsAsync and returns undefined (in-line with our codebase conventions) if the block was not found.

Testing instructions

Types of changes

Checklist:

  • Prefix PR title with [WIP] if necessary.
  • Prefix PR title with bracketed package name(s) corresponding to the changed package(s). For example: [sol-cov] Fixed bug.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • Add new entries to the relevant CHANGELOG.jsons.

"changes": [
{
"note":
"Rename `getBlockAsync` to `getBlockIfExistsAsync` and rather then throw if the requested block wasn't found, return undefined."
Copy link
Contributor

Choose a reason for hiding this comment

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

PR number

@@ -329,23 +329,28 @@ export class Web3Wrapper {
/**
* Fetch a specific Ethereum block without transaction data
* @param blockParam The block you wish to fetch (blockHash, blockNumber or blockLiteral)
* @returns The requested block without transaction data
* @returns The requested block without transaction data, or undefined if block was not found
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment why the block could be not found?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 84.984% when pulling 7516959 on fixGetBlocks into 8bce407 on development.

@fabioberger fabioberger merged commit fc33eac into development Sep 24, 2018
@fabioberger fabioberger deleted the fixGetBlocks branch September 24, 2018 14:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants