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

[Bug] Trying to decode non 200 status code payloads as result object. #253

Closed
Will-Smith11 opened this issue Mar 7, 2024 · 1 comment · Fixed by #254
Closed

[Bug] Trying to decode non 200 status code payloads as result object. #253

Will-Smith11 opened this issue Mar 7, 2024 · 1 comment · Fixed by #254
Labels
bug Something isn't working

Comments

@Will-Smith11
Copy link

Will-Smith11 commented Mar 7, 2024

Component

network, json-rpc, rpc

What version of Alloy are you on?

rev 76c70fb

Operating System

Linux

Describe the bug

When hitting a rate limit on a reth node. Was getting the error: Err(DeserError { err: Error("expected value", line: 1, column: 1). This was very missleading as the message was text: "Too many connections. Please try again later." that comes with a 429 status code. This should be a ErrorResp afaik.

 err=Err(DeserError { err: Error("expected value", line: 1, column: 1), text: "Too many connections. Please try again later." })
#[derive(Debug, Clone)]
pub struct LocalProvider {
    provider: Arc<Provider<Http<reqwest::Client>>>,
    retries:  u8,
}

impl LocalProvider {
    pub fn new(url: String, retries: u8) -> Self {
        let http = Http::new(url.parse().unwrap());

        Self { provider: Arc::new(Provider::new(http)), retries }
    }
}

#[async_trait::async_trait]
impl TracingProvider for LocalProvider {
    async fn eth_call(
        &self,
        request: TransactionRequest,
        block_number: Option<BlockId>,
        state_overrides: Option<StateOverride>,
        block_overrides: Option<Box<BlockOverrides>>,
    ) -> eyre::Result<Bytes> {
        if state_overrides.is_some() || block_overrides.is_some() {
            panic!("local provider doesn't support block or state overrides");
        }
        // for tests, shit can get beefy 
        let mut attempts = 0;
        loop {
            let inner = self.provider.inner();
            let res_str: String = inner
                .prepare("eth_call", (request.clone(), block_number))
                .await
                .unwrap();
            let res = self.provider.call(request.clone(), block_number).await;
            if res.is_ok() || attempts > self.retries {
                return res.map_err(Into::into)
            } else {
                // error message was generated here
                tracing::error!(eth_call_error=%res_str, ?request, err=?res); 
            }
            attempts += 1
        }
    }
}
@Will-Smith11 Will-Smith11 added the bug Something isn't working label Mar 7, 2024
@prestwich
Copy link
Member

This should not be an ErrResp as ErrResp must conform to the JSON-RPC2.0 spec. This should be an Error::custom. Which can be achieved for reqwest using error_for_status, and as a custom error in the hyper transport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants