mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
refactor(gui-client): add more context to connection failures (#7364)
Adding more context to these errors makes it easier to identify, which of the operations fails. In addition, we remove some usages of the "log and return" anti-pattern to avoid duplicate reports of the same issue.
This commit is contained in:
@@ -217,34 +217,35 @@ impl Drop for Tun {
|
||||
}
|
||||
|
||||
impl Tun {
|
||||
#[tracing::instrument(level = "debug")]
|
||||
pub fn new(mtu: u32) -> Result<Self> {
|
||||
let path = ensure_dll()?;
|
||||
fn new(mtu: u32) -> Result<Self> {
|
||||
let path = ensure_dll().context("Failed to ensure `wintun.dll` is in place")?;
|
||||
// SAFETY: we're loading a DLL from disk and it has arbitrary C code in it. There's no perfect way to prove it's safe.
|
||||
let wintun = unsafe { wintun::load_from_path(path) }?;
|
||||
let wintun = unsafe { wintun::load_from_path(path.clone()) }
|
||||
.with_context(|| format!("Failed to load `wintun.dll` from {}", path.display()))?;
|
||||
|
||||
// Create wintun adapter
|
||||
let adapter = match Adapter::create(
|
||||
let adapter = Adapter::create(
|
||||
&wintun,
|
||||
TUNNEL_NAME,
|
||||
TUNNEL_NAME,
|
||||
Some(TUNNEL_UUID.as_u128()),
|
||||
) {
|
||||
Ok(x) => x,
|
||||
Err(error) => {
|
||||
tracing::error!(error = std_dyn_err(&error), "Failed in `Adapter::create`");
|
||||
return Err(error)?;
|
||||
}
|
||||
};
|
||||
let iface_idx = adapter.get_adapter_index()?;
|
||||
)?;
|
||||
let iface_idx = adapter
|
||||
.get_adapter_index()
|
||||
.context("Failed to get adapter index")?;
|
||||
|
||||
set_iface_config(adapter.get_luid(), mtu)?;
|
||||
set_iface_config(adapter.get_luid(), mtu).context("Failed to set interface config")?;
|
||||
|
||||
let session = Arc::new(adapter.start_session(RING_BUFFER_SIZE)?);
|
||||
let session = Arc::new(
|
||||
adapter
|
||||
.start_session(RING_BUFFER_SIZE)
|
||||
.context("Failed to start session")?,
|
||||
);
|
||||
// 4 is a nice power of two. Wintun already queues packets for us, so we don't
|
||||
// need much capacity here.
|
||||
let (packet_tx, packet_rx) = mpsc::channel(4);
|
||||
let recv_thread = start_recv_thread(packet_tx, Arc::clone(&session))?;
|
||||
let recv_thread = start_recv_thread(packet_tx, Arc::clone(&session))
|
||||
.context("Failed to start recv thread")?;
|
||||
|
||||
Ok(Self {
|
||||
iface_idx,
|
||||
|
||||
@@ -9,7 +9,7 @@ use firezone_bin_shared::{
|
||||
platform::{tcp_socket_factory, udp_socket_factory, DnsControlMethod},
|
||||
TunDeviceManager, TOKEN_ENV_KEY,
|
||||
};
|
||||
use firezone_logging::{anyhow_dyn_err, std_dyn_err, telemetry_span};
|
||||
use firezone_logging::{anyhow_dyn_err, telemetry_span};
|
||||
use firezone_telemetry::Telemetry;
|
||||
use futures::{
|
||||
future::poll_fn,
|
||||
@@ -480,12 +480,7 @@ impl<'a> Handler<'a> {
|
||||
// Warning: Connection errors don't bubble to callers of `handle_ipc_msg`.
|
||||
let token = secrecy::SecretString::from(token);
|
||||
let result = self.connect_to_firezone(&api_url, token);
|
||||
if let Err(error) = &result {
|
||||
tracing::error!(
|
||||
error = std_dyn_err(error),
|
||||
"Failed to connect connlib session"
|
||||
);
|
||||
}
|
||||
|
||||
self.ipc_tx
|
||||
.send(&ServerMsg::ConnectResult(result))
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user