From bc1cb9336114b461b20b2a90de6ae431c75a7bf7 Mon Sep 17 00:00:00 2001 From: Cole Mickens Date: Mon, 5 Aug 2024 12:37:50 -0700 Subject: [PATCH] uds: cleanup error reporting to user --- src/cli/cmd/login/mod.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cli/cmd/login/mod.rs b/src/cli/cmd/login/mod.rs index 2bf08a3..cea5d4e 100644 --- a/src/cli/cmd/login/mod.rs +++ b/src/cli/cmd/login/mod.rs @@ -78,7 +78,6 @@ pub async fn dnixd_uds() -> color_eyre::Result> { let response = sender.send_request(request).await?; if response.status() != StatusCode::OK { - tracing::error!("failed to connect to determinate-nixd socket"); return Err(eyre!("failed to connect to determinate-nixd socket")); } @@ -90,10 +89,15 @@ impl LoginSubcommand { let dnixd_uds = match dnixd_uds().await { Ok(socket) => Some(socket), Err(err) => { - tracing::error!( - "failed to connect to determinate-nixd socket, will not attempt to use it: {:?}", - err + if tracing::enabled!(tracing::Level::DEBUG) { + tracing::debug!( + "failed to connect to determinate-nixd socket, will not attempt to use it: {}", err ); + } else { + tracing::warn!( + "failed to connect to determinate-nixd socket, will not attempt to use it." + ); + } None } }; @@ -199,8 +203,6 @@ impl LoginSubcommand { let bytes = body.collect().await.unwrap_or_default().to_bytes(); let text: String = String::from_utf8_lossy(&bytes).into(); - tracing::trace!("sent the add request: {:?}", text); - token_updated = true; } @@ -209,6 +211,11 @@ impl LoginSubcommand { "failed to update netrc via determinatenixd, falling back to local-file approach" ); + // check if user is root or not + if !nix::unistd::Uid::effective().is_root() { + return Err(eyre!("`fh login` is attempting to update a file owned by root, please re-run the same command, prefixed with `sudo -i`.")) + } + update_netrc_file(&netrc_file_path, &netrc_contents).await?; // only update user_nix_config if we could not use determinatenixd