1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Add reason string support to MissingExperimentalFeature

This commit is contained in:
Robert Hensing 2025-10-13 14:09:49 +02:00
parent 583f5e37fc
commit 0fd890a8d6
4 changed files with 9 additions and 7 deletions

View file

@ -500,10 +500,10 @@ bool ExperimentalFeatureSettings::isEnabled(const ExperimentalFeature & feature)
return std::find(f.begin(), f.end(), feature) != f.end();
}
void ExperimentalFeatureSettings::require(const ExperimentalFeature & feature) const
void ExperimentalFeatureSettings::require(const ExperimentalFeature & feature, std::string reason) const
{
if (!isEnabled(feature))
throw MissingExperimentalFeature(feature);
throw MissingExperimentalFeature(feature, std::move(reason));
}
bool ExperimentalFeatureSettings::isEnabled(const std::optional<ExperimentalFeature> & feature) const

View file

@ -1,5 +1,6 @@
#include "nix/util/experimental-features.hh"
#include "nix/util/fmt.hh"
#include "nix/util/strings.hh"
#include "nix/util/util.hh"
#include <nlohmann/json.hpp>
@ -376,10 +377,11 @@ std::set<ExperimentalFeature> parseFeatures(const StringSet & rawFeatures)
return res;
}
MissingExperimentalFeature::MissingExperimentalFeature(ExperimentalFeature feature)
MissingExperimentalFeature::MissingExperimentalFeature(ExperimentalFeature feature, std::string reason)
: Error(
"experimental Nix feature '%1%' is disabled; add '--extra-experimental-features %1%' to enable it",
showExperimentalFeature(feature))
"experimental Nix feature '%1%' is disabled%2%; add '--extra-experimental-features %1%' to enable it",
showExperimentalFeature(feature),
Uncolored(optionalBracket(" (", reason, ")")))
, missingFeature(feature)
{
}

View file

@ -463,7 +463,7 @@ struct ExperimentalFeatureSettings : Config
* Require an experimental feature be enabled, throwing an error if it is
* not.
*/
void require(const ExperimentalFeature &) const;
void require(const ExperimentalFeature &, std::string reason = "") const;
/**
* `std::nullopt` pointer means no feature, which means there is nothing that could be

View file

@ -88,7 +88,7 @@ public:
*/
ExperimentalFeature missingFeature;
MissingExperimentalFeature(ExperimentalFeature missingFeature);
MissingExperimentalFeature(ExperimentalFeature missingFeature, std::string reason = "");
};
/**