1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 03:56:01 +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(); 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)) if (!isEnabled(feature))
throw MissingExperimentalFeature(feature); throw MissingExperimentalFeature(feature, std::move(reason));
} }
bool ExperimentalFeatureSettings::isEnabled(const std::optional<ExperimentalFeature> & feature) const bool ExperimentalFeatureSettings::isEnabled(const std::optional<ExperimentalFeature> & feature) const

View file

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

View file

@ -463,7 +463,7 @@ struct ExperimentalFeatureSettings : Config
* Require an experimental feature be enabled, throwing an error if it is * Require an experimental feature be enabled, throwing an error if it is
* not. * 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 * `std::nullopt` pointer means no feature, which means there is nothing that could be

View file

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