Skip to content

Commit 4ff8668

Browse files
authored
Merge pull request #208 from antifuchs/push-qounzrwtmykk
import-flake, update: Add the pin that an error is about as context
2 parents 2449cd0 + 9bc41f8 commit 4ff8668

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/main.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,13 @@ impl Opts {
669669
"Writing initial lock file with nixpkgs entry (need to fetch latest commit first)"
670670
);
671671
let mut pin = NixPins::new_with_nixpkgs();
672-
Self::update_one(pin.pins.get_mut("nixpkgs").unwrap(), UpdateStrategy::Full)
673-
.await
674-
.context("Failed to fetch initial nixpkgs entry")?;
672+
Self::update_one(
673+
"nixpkgs",
674+
pin.pins.get_mut("nixpkgs").unwrap(),
675+
UpdateStrategy::Full,
676+
)
677+
.await
678+
.context("Failed to fetch initial nixpkgs entry")?;
675679
pin
676680
};
677681
self.write_pins(&initial_pins)?;
@@ -739,7 +743,7 @@ impl Opts {
739743
} else {
740744
UpdateStrategy::Full
741745
};
742-
Self::update_one(&mut pin, strategy)
746+
Self::update_one(&name, &mut pin, strategy)
743747
.await
744748
.context("Failed to fully initialize the pin")?;
745749
pins.pins.insert(name.clone(), pin.clone());
@@ -751,17 +755,26 @@ impl Opts {
751755
Ok(())
752756
}
753757

754-
async fn update_one(pin: &mut Pin, strategy: UpdateStrategy) -> Result<Vec<diff::DiffEntry>> {
758+
async fn update_one(
759+
name: &str,
760+
pin: &mut Pin,
761+
strategy: UpdateStrategy,
762+
) -> Result<Vec<diff::DiffEntry>> {
755763
/* Skip this for partial updates */
756764
let diff1 = if strategy.should_update() {
757-
pin.update().await?
765+
pin.update()
766+
.await
767+
.with_context(|| format!("Updating {}", name))?
758768
} else {
759769
vec![]
760770
};
761771

762772
/* We only need to fetch the hashes if the version changed, or if the flags indicate that we should */
763773
let diff = if !diff1.is_empty() || strategy.must_fetch() {
764-
let diff2 = pin.fetch().await?;
774+
let diff2 = pin
775+
.fetch()
776+
.await
777+
.with_context(|| format!("Fetching {}", name))?;
765778
diff1.into_iter().chain(diff2.into_iter()).collect()
766779
} else {
767780
diff1
@@ -825,7 +838,7 @@ impl Opts {
825838
})
826839
.map(|(name, pin)| async move {
827840
animation.on_pin_start(name);
828-
let diff = Self::update_one(pin, strategy).await?;
841+
let diff = Self::update_one(name, pin, strategy).await?;
829842
animation.on_pin_finish(name, |stderr| write_diff(stderr, name, &diff));
830843
anyhow::Result::<_, anyhow::Error>::Ok((name, diff))
831844
});
@@ -898,7 +911,7 @@ impl Opts {
898911
.filter(|(name, _pin)| selected_pins.contains(name) || opts.names.is_empty())
899912
.map(|(name, pin)| async move {
900913
animation.on_pin_start(name);
901-
let diff_result = Self::update_one(pin, STRATEGY).await;
914+
let diff_result = Self::update_one(name, pin, STRATEGY).await;
902915
animation.on_pin_finish(name, |stderr| match &diff_result {
903916
Ok(diff) => write_diff(stderr, name, diff),
904917
Err(err) => {
@@ -1191,7 +1204,8 @@ impl Opts {
11911204
&mut pins,
11921205
nodes,
11931206
)
1194-
.await?;
1207+
.await
1208+
.with_context(|| format!("Importing flake input {name}"))?;
11951209
} else {
11961210
for (name, input_name) in inputs.iter() {
11971211
log::info!("Importing {}", name);

0 commit comments

Comments
 (0)