-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Util, Block: added Util error module, first exemplary BlockHeader err…
…or implementation
- Loading branch information
1 parent
58e68b9
commit 95b6b8b
Showing
4 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { EthereumJSError } from '@ethereumjs/util' | ||
|
||
export enum HeaderValidationErrorCode { | ||
WRONG_TX_TRIE_LENGTH = 'WRONG_TX_TRIE_LENGTH', | ||
} | ||
|
||
export type HeaderValidationErrorType = { | ||
block: string | ||
received: string | ||
} | ||
|
||
export class HeaderValidationError extends EthereumJSError<HeaderValidationErrorType> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Generic EthereumJS error with metadata attached | ||
* | ||
* Kudos to https://github.com/ChainSafe/lodestar monorepo | ||
* for the inspiration :-) | ||
*/ | ||
export class EthereumJSError<T extends {}> extends Error { | ||
code: string | ||
errorContext: T | ||
|
||
constructor(msg: string, code: string, errorContext: T) { | ||
super(msg) | ||
this.code = code | ||
this.errorContext = errorContext | ||
} | ||
|
||
getErrorContext(): Record<string, string | number | null> { | ||
return { code: this.code, ...this.errorContext } | ||
} | ||
|
||
/** | ||
* Get the metadata and the stacktrace for the error. | ||
*/ | ||
toObject(): Record<string, string | number | null> { | ||
return { | ||
...this.getErrorContext(), | ||
stack: this.stack ?? '', | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters