subtensor icon indicating copy to clipboard operation
subtensor copied to clipboard

UI and python client get the error types and error docs from metadata

Open sam0x17 opened this issue 1 year ago • 6 comments
trafficstars

It's pretty annoying that the UI doesn't know at all what errors are if they haven't been hard-coded. Unknown error isn't a great user experience, and right now introducing new error types or errors in new situations creates a lot of churn with releases.

Substrate provides the metadata, which includes all info about errors, calls and events. At first, we must guarantee all of them are well documented. In this issue, all docs for errors are checked.

From this unit test file for metadata check, the structure is clear for other language like python and js to parse. https://github.com/opentensor/subtensor/blob/development/runtime/tests/metadata.rs

  • [x] add these as doc comments for the errors
  • [x] add unit test in the runtime to guarantee docs is ok for new added errors
  • [x] profit?

fixes #375

sam0x17 avatar Apr 30 '24 15:04 sam0x17

Synced with the @opentensor/cortex peeps, this is how we will pass it to them:

We will add an RPC call that produces a JSON map of all error codes => { name, description } for each error. Client will hold off on calling this RPC endpoint until the first time they encounter an error, then they will hit the endpoint and cache the map (probably in a local file). Later, if they ever hit an error code that isn't in their local map, they will hit the endpoint again. In this way, we will always be able to display names and descriptions for errors coming from subtensor, even if new ones are introduced in a chain upgrade that bittensor doesn't specifically know about.

cc @unconst ^

so data coming back from that endpoint will look something like:

{
    "0": {
        "name": "SomeError",
        "description": "Thrown when yeet and something something"
    },
    "1": {
        "name": "AnotherError",
        "description": "This is a description something something"
    },
    "2": {
        "name": "YetAnotherError",
        "description": "This is a description something something"
    }
}

sam0x17 avatar May 01 '24 00:05 sam0x17

I would recommend doing something like this rather than Display actually:

pub trait SubtensorError {
    const NAME: &'static str;
    const DESCRIPTION: &'static str;
}

sam0x17 avatar May 02 '24 17:05 sam0x17

Related : https://github.com/opentensor/subtensor/issues/375 cc @camfairchild

distributedstatemachine avatar May 04 '24 15:05 distributedstatemachine

partially fixed by #391

sam0x17 avatar May 06 '24 18:05 sam0x17

right now it looks like the way forward is actually just using regular substrate metadata, which @open-junius has implemented in #391

sam0x17 avatar May 06 '24 18:05 sam0x17

From this unit test file for metadata, the structure is clear for other language like python to parse. https://github.com/opentensor/subtensor/blob/development/runtime/tests/metadata.rs

open-junius avatar May 07 '24 12:05 open-junius