CodecError
A value that does not match its method’s schema: params that cannot be encoded, in which case nothing was sent, or a result the node sent in an unexpected shape.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
// A block count must be a non-negative integer.const history = Eth.feeHistory(-1, "latest", []).pipe( Effect.catchTag("CodecError", (error) => Effect.succeed(`${error.method}: bad ${error.on}`), // "eth_feeHistory: bad params" ),);Properties
Section titled “Properties”| Property | Type | Holds |
|---|---|---|
_tag |
"CodecError" |
the tag Effect.catchTag matches |
method |
string |
the wire name of the method |
on |
"params" | "result" |
which side failed |
value |
unknown |
what failed, as it was: the params as given, or the result as it was received |
cause |
Schema.SchemaError |
the schema failure, with the path of the value that did not fit |
message |
string |
Invalid params for eth_feeHistory: …, built from on, method and cause |
The message of the example above, as it prints:
Invalid params for eth_feeHistory: Expected a value between 0 and 9007199254740991 at [0]value stays out of the message, which it could make large. Read it to see what a node or a
wallet really sent:
import { Effect } from "effect";import { Wallet } from "@ethect/core/rpc";
const status = (id: string) => Wallet.getCallsStatus(id).pipe( Effect.tapErrorTag("CodecError", (error) => Effect.logWarning(`${error.method} answered`, error.value), ), );When it is raised
Section titled “When it is raised”on |
Cause | Was anything sent? |
|---|---|---|
"params" |
an argument is outside what its schema allows: a negative quantity, a number that is not a safe integer, hex of the wrong length |
no |
"result" |
the node answered, and the answer does not have the shape the method promises | yes, and the node executed the call |
TypeScript catches most wrong arguments first. A CodecError on params is for what types
cannot express, such as the sign of a bigint.
Behavior
Section titled “Behavior”- Unknown fields are not an error. A result with extra fields decodes, and the extra fields are dropped. Only a missing or mistyped field fails.
- A key set to
undefinedis an absent key. Only a provider in the page can send one, since JSON drops it: it is read as if it were left out. Nothing is ever encoded asundefined. - A wallet’s answer is the cause of a
SignerError. What a signer cannot read of a wallet’s answer fails with aSignerError"Unknown"whosecauseis this error, and whose message names the method. - A result error is often a chain difference. A chain whose blocks or transactions lack a field the schema requires fails here. Define the method again with a schema of that chain: see Custom methods.
- Subscriptions and events too. An item pushed by a subscription that does not fit fails
the stream with a
CodecErrorwhosemethodiseth_subscribe. A payload of anEip1193event stream that does not fit fails it with the event name asmethod.
| Type | Is |
|---|---|
CodecError.CodecError |
the error class |