Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unstructured errors returned from query RPC method #6384

Closed
miraclx opened this issue Mar 4, 2022 · 0 comments · Fixed by near/near-jsonrpc-client-rs#82
Closed

Unstructured errors returned from query RPC method #6384

miraclx opened this issue Mar 4, 2022 · 0 comments · Fixed by near/near-jsonrpc-client-rs#82
Labels
A-RPC Area: rpc C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@miraclx
Copy link
Contributor

miraclx commented Mar 4, 2022

Describe the bug

Following #3944, the process_query_response method was introduced to maintain backwards compatibility when reporting some variants of QueryError.

/// This function processes response from query method to introduce
/// backward compatible response in case of specific errors
fn process_query_response(

The implication of this, is that, instead of the server returning structured errors in the VErr format (#2976), it returns a custom JSON response with the error contained inside a string. And worse of all, under the guise of a "result" instead of an "error".

// $ http ... method=query params='{"request_type":"view_access_key","account_id":"test.near","public_key":"..."}'
{
    "jsonrpc": "2.0",
    "result": { // <-- returns "result" instead of "error"
        "block_hash": "HZUfyFnKD8uneRDc8LYWe2xxMWFBYj2oxes3iZuwYAPX",
        "block_height": 84145708,
        "error": "access key ed25519:J9rU3yZhwZB3UriwvETEcuf1a7FyS3sz5sTsmH2z8zTe does not exist while viewing",
        "logs": []
    },
    "id": "dontcare"
}

Expected behavior

I personally feel we should migrate totally off unstructured server responses and have something to the effect of:

// $ http ... method=query params='{"request_type":"view_access_key","account_id":"test.near","public_key":"..."}'
{
    "jsonrpc": "2.0",
    "error": {
        "name": "HANDLER_ERROR",
        "cause": {
            "info": {
                "public_key": "ed25519:J9rU3yZhwZB3UriwvETEcuf1a7FyS3sz5sTsmH2z8zTe",
                "block_height": 84145708,
                "block_hash": "HZUfyFnKD8uneRDc8LYWe2xxMWFBYj2oxes3iZuwYAPX"
            },
            "name": "UNKNOWN_ACCESS_KEY"
        },
        "code": -32000,
        "message": "Server error",
        "data": "access key ed25519:J9rU3yZhwZB3UriwvETEcuf1a7FyS3sz5sTsmH2z8zTe does not exist while viewing"
    },
    "id": "dontcare"
}

Additional context

The extended impact of this, is, on near-jsonrpc-client, when deserializing the server response back into the RpcQueryError structure, it fails from attempting to parse the unstructured data the server responds with.

cc: @frol @khorolets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-RPC Area: rpc C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant