From bf856ae627d9bb6006a190c3a74b130afe81d5fd Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Mon, 15 Apr 2024 10:15:17 +0200 Subject: [PATCH] fix: improve error on parsing lockfile (#1180) --- src/lock_file/mod.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lock_file/mod.rs b/src/lock_file/mod.rs index 845b4006c..306ec0ac2 100644 --- a/src/lock_file/mod.rs +++ b/src/lock_file/mod.rs @@ -9,7 +9,7 @@ mod satisfiability; mod update; use crate::Project; -use miette::IntoDiagnostic; +use miette::{IntoDiagnostic, WrapErr}; use rattler_conda_types::RepoDataRecord; use rattler_lock::{LockFile, PypiPackageData, PypiPackageEnvironmentData}; @@ -35,9 +35,18 @@ pub async fn load_lock_file(project: &Project) -> miette::Result { let lock_file_path = project.lock_file_path(); if lock_file_path.is_file() { // Spawn a background task because loading the file might be IO bound. - tokio::task::spawn_blocking(move || LockFile::from_path(&lock_file_path).into_diagnostic()) - .await - .unwrap_or_else(|e| Err(e).into_diagnostic()) + tokio::task::spawn_blocking(move || { + LockFile::from_path(&lock_file_path) + .into_diagnostic() + .wrap_err_with(|| { + format!( + "Failed to load lock file from `{}`", + lock_file_path.display() + ) + }) + }) + .await + .unwrap_or_else(|e| Err(e).into_diagnostic()) } else { Ok(LockFile::default()) }