mirror of https://github.com/mamba-org/mamba.git
More details in error message when failing to parse json from a python command's output (#3604)
This commit is contained in:
parent
6467000748
commit
20d51bb0c5
|
@ -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<BuildNumberPredicate>;
|
||||
friend struct ::fmt::formatter<BuildNumberPredicate>;
|
||||
};
|
||||
|
||||
auto operator==(const BuildNumberPredicate& lhs, const BuildNumberPredicate& rhs) -> bool;
|
||||
|
@ -140,7 +140,7 @@ namespace mamba::specs
|
|||
|
||||
BuildNumberPredicate m_predicate;
|
||||
|
||||
friend class ::fmt::formatter<BuildNumberSpec>;
|
||||
friend struct ::fmt::formatter<BuildNumberSpec>;
|
||||
};
|
||||
|
||||
namespace build_number_spec_literals
|
||||
|
|
|
@ -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<VersionPredicate>;
|
||||
friend struct ::fmt::formatter<VersionPredicate>;
|
||||
};
|
||||
|
||||
auto operator==(const VersionPredicate& lhs, const VersionPredicate& rhs) -> bool;
|
||||
|
@ -210,7 +210,7 @@ namespace mamba::specs
|
|||
|
||||
tree_type m_tree;
|
||||
|
||||
friend class ::fmt::formatter<VersionSpec>;
|
||||
friend struct ::fmt::formatter<VersionSpec>;
|
||||
};
|
||||
|
||||
namespace version_spec_literals
|
||||
|
|
|
@ -9,9 +9,11 @@
|
|||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
#include <fmt/ranges.h>
|
||||
#include <reproc++/run.hpp>
|
||||
|
||||
#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"
|
||||
|
@ -223,15 +225,27 @@ 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)
|
||||
{
|
||||
throw std::runtime_error(ec.message());
|
||||
const auto message = fmt::format(
|
||||
"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, " "),
|
||||
out,
|
||||
err
|
||||
);
|
||||
throw mamba_error{ message, mamba_error_code::internal_failure };
|
||||
}
|
||||
|
||||
// Nothing installed with `pip`
|
||||
|
@ -241,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())
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue