Skip to content

Commit 381d490

Browse files
committed
Implement some recommendations from copilot
1 parent fac01dc commit 381d490

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

src/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn display_diff(
7070
size_old,
7171
size_new,
7272
})?;
73-
print!("{json}");
73+
println!("{json}");
7474
Ok(())
7575
}
7676

src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ struct Cli {
5959
#[arg(long, default_value_t = false, global = true)]
6060
force_correctness: bool,
6161

62-
/// Does not display the normal, human readable diff, but rather
63-
/// serialized to json
62+
/// Outputs the diff in JSON format instead of the normal, human-readable diff.
6463
///
6564
/// Requires the "json" feature.
6665
#[arg(long, default_value_t = false, global = true)]

src/store.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ mod db_lazy;
88
mod nix_command;
99
mod queries;
1010

11-
pub mod store {
12-
pub use crate::store::db_lazy::LazyDBConnection;
13-
}
14-
1511
use std::{
1612
fmt::Display,
1713
iter::Iterator,
@@ -25,13 +21,11 @@ use anyhow::{
2521
use log::warn;
2622
use size::Size;
2723

28-
use crate::{
29-
StorePath,
30-
store::{
31-
db_eager::EagerDBConnection,
32-
nix_command::CommandBackend,
33-
store::LazyDBConnection,
34-
},
24+
use crate::StorePath;
25+
pub use crate::store::{
26+
db_eager::EagerDBConnection,
27+
db_lazy::LazyDBConnection,
28+
nix_command::CommandBackend,
3529
};
3630
/// The normal database connection
3731
pub const DATABASE_PATH: &str = "file:/nix/var/nix/db/db.sqlite";

src/store/nix_command.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn nix_command_query<'a>(
5757
}
5858

5959
impl<'a> StoreBackend<'a> for CommandBackend {
60-
/// Does nothing (we spawn a new process everytime).
60+
/// Does nothing (we spawn a new process every time).
6161
fn connect(&mut self) -> Result<()> {
6262
Ok(())
6363
}
@@ -80,6 +80,15 @@ impl<'a> StoreBackend<'a> for CommandBackend {
8080
.arg(path.join("sw"))
8181
.output()
8282
.context(anyhow!("Encountered error while executing nix command"))?;
83+
84+
if !cmd_res.status.success() {
85+
let stderr = String::from_utf8_lossy(&cmd_res.stderr);
86+
return Err(anyhow!(
87+
"nix command exited with non-zero status {}: {}",
88+
cmd_res.status,
89+
stderr.trim()
90+
));
91+
}
8392
let text = str::from_utf8(&cmd_res.stdout)?;
8493
if let Some(bytes_text) = text.split_whitespace().last()
8594
&& let Ok(bytes) = bytes_text.parse::<u64>()

0 commit comments

Comments
 (0)