mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
networkdoctor: flesh out messaging a bit
Summary: Add better error formatting and add user visible "treatment" (i.e. tips/instructions on how to resolve the problem). Reviewed By: DurhamG Differential Revision: D34649752 fbshipit-source-id: 26a3ab77084ceeaac2eb6cf5ae31c01760645ad8
This commit is contained in:
parent
f895dcbef1
commit
f4dee7947f
@ -7,4 +7,5 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
configmodel = { version = "0.1.0", path = "../../configmodel" }
|
||||
thiserror = "1.0.29"
|
||||
url = "2.2.2"
|
||||
|
@ -14,23 +14,46 @@ use std::vec;
|
||||
|
||||
use configmodel::Config;
|
||||
use configmodel::ConfigExt;
|
||||
use thiserror::Error;
|
||||
use url::Host;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum HostError {
|
||||
#[error("invalid host config: {0}")]
|
||||
Config(String),
|
||||
#[error("DNS error: {0}")]
|
||||
DNS(io::Error),
|
||||
#[error("TCP error: {0}")]
|
||||
TCP(io::Error),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Diagnosis {
|
||||
#[error("invalid config: {0}")]
|
||||
BadConfig(String),
|
||||
#[error("no internet connectivity: {0}")]
|
||||
NoInternet(HostError),
|
||||
#[error("no corp connectivity: {0}")]
|
||||
NoCorp(HostError),
|
||||
}
|
||||
|
||||
impl Diagnosis {
|
||||
pub fn treatment(&self) -> String {
|
||||
match self {
|
||||
Self::NoCorp(_) => {
|
||||
"Please check your VPN connection (internet okay, but can't reach corp)."
|
||||
.to_string()
|
||||
}
|
||||
Self::NoInternet(_) => {
|
||||
"Please check your internet connection (failed external connectivity test)."
|
||||
.to_string()
|
||||
}
|
||||
Self::BadConfig(msg) => format!("Invalid config: {}", msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Doctor {
|
||||
// Allow tests to stub DNS responses.
|
||||
dns_lookup: Box<dyn Fn(&str) -> io::Result<vec::IntoIter<SocketAddr>>>,
|
||||
|
Loading…
Reference in New Issue
Block a user