-
Notifications
You must be signed in to change notification settings - Fork 10
fix: added error handling for connection issues #56
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
base: master
Are you sure you want to change the base?
Conversation
match url::Url::parse(s) { | ||
Ok(url) => Ok(url), | ||
Err(e) => { | ||
let error_msg = e.to_string().to_lowercase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you match on url::ParseError
instead? Matching by string value seems brittle and unnecessary
|
||
/// Custom URL parser that adds http:// prefix if missing | ||
fn parse_url(s: &str) -> Result<url::Url, String> { | ||
// Check if the URL already has a scheme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the scheme must be http
, then perhaps we should only be parsing a url::Host
and port (u16
), and adding the scheme ourselves
@@ -107,6 +362,73 @@ pub struct Cli { | |||
#[command(subcommand)] | |||
pub command: Command, | |||
} | |||
|
|||
/// Custom URL parser that adds http:// prefix if missing | |||
fn parse_url(s: &str) -> Result<url::Url, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this have a custom error type? Using String
seems brittle and limiting
let rpc_url = self.rpc_url.clone(); | ||
|
||
// Build the client and handle connection errors | ||
let client = builder.build(self.rpc_url.clone()).map_err(|err| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to match on the error here?
.await | ||
.map_err(|err| { | ||
// Check if this is a connection error that happened during the request | ||
if let Some(client_err) = err.downcast_ref::<jsonrpsee::core::ClientError>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Downcasting here is very brittle. You probably want to match on the actual errors, so that you can display the correct error message for wrapped errors
This PR addresses issue #11 by improving the error handling for connection issues in the CLI.
Added:
CliError
to handle connection errors more gracefullyhttp://
protocol prefixExample DNS Issue:
Connection Refused:
Connection Timeout: