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:
Muir Manders 2022-03-17 11:11:53 -07:00 committed by Facebook GitHub Bot
parent f895dcbef1
commit f4dee7947f
2 changed files with 26 additions and 2 deletions

View File

@ -7,4 +7,5 @@ edition = "2021"
[dependencies]
configmodel = { version = "0.1.0", path = "../../configmodel" }
thiserror = "1.0.29"
url = "2.2.2"

View File

@ -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>>>,