polkadot-js / api

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.
Apache License 2.0
1.06k stars 350 forks source link

How to display event error enum instead of error index ? #2109

Closed clearloop closed 4 years ago

clearloop commented 4 years ago

Desc

For example:

 𝝺 ts-node relay.ts
✔ Test which process? › Relay header
2020-03-28 08:57:58        API/INIT: RPC methods not decorated: babe_epochAuthorship, contracts_rentProjection, offchain_localStorageGet, offchain_localStorageSet, state_getPairs, system_addReservedPeer, system_nodeRoles, system_removeReservedPeer}
[ success ]: init darwinia account 🧙‍♂️
[ info ] Transaction status: Ready
[ info ] Transaction status: InBlock
[ info ] Included at block hash: 0xe4b812bea47df983df7b4be2950275aea047f5d60d22de0177ed27ffb8f78a23
[ info ]        {"ApplyExtrinsic":2}: treasury.DepositRing[86488616]
[ info ]        {"ApplyExtrinsic":2}: system.ExtrinsicFailed[{"Module":{"index":25,"error":10}},{"weight":100000,"class":"Normal","paysFee":true}]
[ error ]: relay header failed!

The {"Module":{"index":25,"error":10}} is not friendly for testing.

And more...

How to hide the default polkadot API log?

2020-03-28 08:57:58        API/INIT: RPC methods not decorated: babe_epochAuthorship, contracts_rentProjection, offchain_localStorageGet, offchain_localStorageSet, state_getPairs, system_addReservedPeer, system_nodeRoles, system_removeReservedPeer}

This breaks my formats.

jacogr commented 4 years ago
  1. error.isModule && console.error(api.registry.findMetaError(error.asModule))
  2. 1.8.1 has support for all RPCs (as of day of release), 1.9-beta has support for all current master RPCs
clearloop commented 4 years ago
error.isModule && console.error(api.registry.findMetaError(error.asModule))

Thanks!!! It works!

For example, my current code is like:

function parseRes(r: any) {
    let status = r.status;
    log(`Transaction status: ${status.type}`);

    if (status.isInBlock) {
        log(`Included at block hash: ${status.asInBlock.toHex()}`);
        r.events && r.events.forEach(async (r: any) => {
            log(
                "\t" +
                r.phase.toString() +
                `: ${r.event.section}.${r.event.method}` +
                r.event.data.toString()
            );

            // error   
            if (r.event.data[0].isModule) {
                let doc = await this.api.registry.findMetaError(r.event.data[0].asModule);
                let err = `${doc.name}.${doc.section} - ${doc.documentation.join(" ")}`
                log(err, Logger.Error);
                process.exit(1);
            }
        });
    } else if (status.isFinalized) {
        log(`Finalized block hash: ${status.asFinalized.toHex()}`);
        this.queue.active = false;
        this.queue.finished = true;
    }
}

It would be nice to mention this in https://polkadot.js.org/api/ and add something like a search box to find docs by keyword efficiently~

jacogr commented 4 years ago

Agreed. So the reality is that I can either code, or write docs - so atm with all the changes, docs are lagging a lot.

Having said all that - PRs are really very welcome to enhance. I love anything, code, docs.

clearloop commented 4 years ago

Agreed. So the reality is that I can either code, or write docs - so atm with all the changes, docs are lagging a lot.

Me too, I don't even have time to code for fun, things just come as they are one by one, I wish that I can separate another my self firing to the doc/code, frontend business is just so much complex.

jacogr commented 4 years ago

:)

I think things should die down a bit when Substrate 2.x is out the door - that will give a gap to catch up here, a helluva lot of gaps for new stuff atm :( I left pointers in the CHANGELOGs, but without reading, stuff is just hidden.

Will get there.

polkadot-js-bot commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.