Skip to content

Commit 1780425

Browse files
committed
uds: cleanup error reporting to user
1 parent 5898cf2 commit 1780425

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/cli/cmd/login/mod.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ pub async fn dnixd_uds() -> color_eyre::Result<SendRequest<axum::body::Body>> {
7878
let response = sender.send_request(request).await?;
7979

8080
if response.status() != StatusCode::OK {
81-
tracing::error!("failed to connect to determinate-nixd socket");
8281
return Err(eyre!("failed to connect to determinate-nixd socket"));
8382
}
8483

@@ -90,10 +89,15 @@ impl LoginSubcommand {
9089
let dnixd_uds = match dnixd_uds().await {
9190
Ok(socket) => Some(socket),
9291
Err(err) => {
93-
tracing::error!(
94-
"failed to connect to determinate-nixd socket, will not attempt to use it: {:?}",
95-
err
92+
if tracing::enabled!(tracing::Level::DEBUG) {
93+
tracing::debug!(
94+
"failed to connect to determinate-nixd socket, will not attempt to use it: {}", err
9695
);
96+
} else {
97+
tracing::warn!(
98+
"failed to connect to determinate-nixd socket, will not attempt to use it."
99+
);
100+
}
97101
None
98102
}
99103
};
@@ -194,12 +198,16 @@ impl LoginSubcommand {
194198
.header("Content-Type", "application/json")
195199
.body(Body::from(add_req_json))?;
196200
let response = uds.send_request(request).await?;
197-
198-
let body = response.into_body();
199-
let bytes = body.collect().await.unwrap_or_default().to_bytes();
200-
let text: String = String::from_utf8_lossy(&bytes).into();
201-
202-
tracing::trace!("sent the add request: {:?}", text);
201+
202+
if response.status() != StatusCode::OK {
203+
let body = response.into_body();
204+
let bytes = body.collect().await.unwrap_or_default().to_bytes();
205+
let text: String = String::from_utf8_lossy(&bytes).into();
206+
207+
tracing::warn!(
208+
"failed to update netrc via determinatenixd, falling back to local-file approach: {}", &text
209+
);
210+
}
203211

204212
token_updated = true;
205213
}
@@ -209,6 +217,11 @@ impl LoginSubcommand {
209217
"failed to update netrc via determinatenixd, falling back to local-file approach"
210218
);
211219

220+
// check if user is root or not
221+
if !nix::unistd::Uid::effective().is_root() {
222+
return Err(eyre!("`fh login` is attempting to update a file owned by root, please re-run the same command, prefixed with `sudo -i`."));
223+
}
224+
212225
update_netrc_file(&netrc_file_path, &netrc_contents).await?;
213226

214227
// only update user_nix_config if we could not use determinatenixd

0 commit comments

Comments
 (0)