From a64d09b65b0e2677a0a7755369d8a1e21d8c1888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:09:02 +0100 Subject: [PATCH 1/4] fixed warnings --- libmamba/include/mamba/specs/build_number_spec.hpp | 4 ++-- libmamba/include/mamba/specs/version_spec.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libmamba/include/mamba/specs/build_number_spec.hpp b/libmamba/include/mamba/specs/build_number_spec.hpp index ddb1e717ca..5683df5b9b 100644 --- a/libmamba/include/mamba/specs/build_number_spec.hpp +++ b/libmamba/include/mamba/specs/build_number_spec.hpp @@ -73,7 +73,7 @@ namespace mamba::specs friend auto equal(free_interval, free_interval) -> bool; friend auto operator==(const BuildNumberPredicate& lhs, const BuildNumberPredicate& rhs) -> bool; - friend class ::fmt::formatter; + friend struct ::fmt::formatter; }; auto operator==(const BuildNumberPredicate& lhs, const BuildNumberPredicate& rhs) -> bool; @@ -140,7 +140,7 @@ namespace mamba::specs BuildNumberPredicate m_predicate; - friend class ::fmt::formatter; + friend struct ::fmt::formatter; }; namespace build_number_spec_literals diff --git a/libmamba/include/mamba/specs/version_spec.hpp b/libmamba/include/mamba/specs/version_spec.hpp index 50c1b746cf..bb4fccc962 100644 --- a/libmamba/include/mamba/specs/version_spec.hpp +++ b/libmamba/include/mamba/specs/version_spec.hpp @@ -110,7 +110,7 @@ namespace mamba::specs friend auto operator==(not_starts_with, not_starts_with) -> bool; friend auto operator==(compatible_with, compatible_with) -> bool; friend auto operator==(const VersionPredicate& lhs, const VersionPredicate& rhs) -> bool; - friend class ::fmt::formatter; + friend struct ::fmt::formatter; }; auto operator==(const VersionPredicate& lhs, const VersionPredicate& rhs) -> bool; @@ -210,7 +210,7 @@ namespace mamba::specs tree_type m_tree; - friend class ::fmt::formatter; + friend struct ::fmt::formatter; }; namespace version_spec_literals From bedd0aa28abc632771e400fec411c43ca88f948b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:09:48 +0100 Subject: [PATCH 2/4] add more details in error report when failing to parse python's json output --- libmamba/src/core/prefix_data.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libmamba/src/core/prefix_data.cpp b/libmamba/src/core/prefix_data.cpp index 807a03d028..8d4ba77fdc 100644 --- a/libmamba/src/core/prefix_data.cpp +++ b/libmamba/src/core/prefix_data.cpp @@ -10,8 +10,10 @@ #include #include +#include #include "mamba/core/channel_context.hpp" +#include "mamba/core/error_handling.hpp" #include "mamba/core/output.hpp" #include "mamba/core/prefix_data.hpp" #include "mamba/core/util.hpp" @@ -231,7 +233,15 @@ namespace mamba ); if (ec) { - throw std::runtime_error(ec.message()); + const auto message = fmt::format( + "failed to parse python command output:\n error: {}\n command ran: {}\n env options:{}\n-> output to parse:\n{}\n\n-> error output:{}", + ec.message(), + fmt::join(args, " "), + fmt::join(env, " "), + out, + err + ); + throw mamba_error{ message, mamba_error_code::internal_failure }; } // Nothing installed with `pip` From a7377db6a8b7f4c402d964ccac2729a20e0822e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:47:47 +0100 Subject: [PATCH 3/4] augment the right failure --- libmamba/src/core/prefix_data.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libmamba/src/core/prefix_data.cpp b/libmamba/src/core/prefix_data.cpp index 8d4ba77fdc..c1fd24ad4a 100644 --- a/libmamba/src/core/prefix_data.cpp +++ b/libmamba/src/core/prefix_data.cpp @@ -225,16 +225,20 @@ namespace mamba reproc::options run_options; run_options.env.extra = reproc::env{ env }; + LOG_TRACE << "Running command: " + << fmt::format("{}\n env options:{}", fmt::join(args, " "), fmt::join(env, " ")); + auto [status, ec] = reproc::run( args, run_options, reproc::sink::string(out), reproc::sink::string(err) ); + if (ec) { const auto message = fmt::format( - "failed to parse python command output:\n error: {}\n command ran: {}\n env options:{}\n-> output to parse:\n{}\n\n-> error output:{}", + "failed to run python command :\n error: {}\n command ran: {}\n env options:{}\n-> output:\n{}\n\n-> error output:{}", ec.message(), fmt::join(args, " "), fmt::join(env, " "), @@ -251,7 +255,24 @@ namespace mamba return; } - nlohmann::json j = nlohmann::json::parse(out); + LOG_TRACE << "Parsing `pip inspect` output:\n" << out; + nlohmann::json j; + try + { + j = nlohmann::json::parse(out); + } + catch (const std::exception& ec) + { + const auto message = fmt::format( + "failed to parse python command output:\n error: {}\n command ran: {}\n env options:{}\n-> output:\n{}\n\n-> error output:{}", + ec.what(), + fmt::join(args, " "), + fmt::join(env, " "), + out, + err + ); + throw mamba_error{ message, mamba_error_code::internal_failure }; + } if (j.contains("installed") && j["installed"].is_array()) { From ca949f893d70ed95c035565f33caed95b777f835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaim=20=28Jo=C3=ABl=20Lamotte=29?= <142265+Klaim@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:53:33 +0100 Subject: [PATCH 4/4] formatting --- libmamba/src/core/prefix_data.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmamba/src/core/prefix_data.cpp b/libmamba/src/core/prefix_data.cpp index c1fd24ad4a..00d8c4dab5 100644 --- a/libmamba/src/core/prefix_data.cpp +++ b/libmamba/src/core/prefix_data.cpp @@ -9,8 +9,8 @@ #include #include -#include #include +#include #include "mamba/core/channel_context.hpp" #include "mamba/core/error_handling.hpp"