CLI: report configuration values that were substituted with defaults (#16305)

When a preset or a 3mf has an enum or bool value this build cannot parse, the config loader replaces it and records a substitution. The CLI only logged these at info level, which the default log level filters out. A preset with an invalid ironing_type therefore sliced with ironing off, printed nothing and exited 0.

Each substitution is now printed to stderr and added to result.json's warnings array with the class config_value_substituted. Exit codes are unchanged, and --strict does not escalate these warnings. test_cli_strict.sh has a new case for it.
This commit is contained in:
packerlschupfer authored and GitHub committed 2026-10-26 21:35:55 -05:00
1 parent 35235d9a43
commit adea4e48a6
2 files changed
+93 -22

No files matched your search

+18 -9
View File
@@ -517,6 +517,21 @@ static void cli_record_warning(sliced_info_t &sliced_info, const std::string &cl
sliced_info.warnings.push_back(std::move(details));
}
// Reports each config value that could not be parsed and was replaced.
static void cli_report_config_substitutions(const std::string &file, const ConfigSubstitutions &substitutions,
sliced_info_t &sliced_info)
{
for (const ConfigSubstitution &subst : substitutions) {
const std::string new_value = subst.new_value->serialize();
boost::nowide::cerr << "warning: " << file << ": value \"" << subst.old_value << "\" for "
<< subst.opt_def->opt_key << " is not valid, using \"" << new_value
<< "\" instead" << std::endl;
cli_record_warning(sliced_info, "config_value_substituted",
nlohmann::json{{"file", file}, {"key", subst.opt_def->opt_key},
{"old_value", subst.old_value}, {"new_value", new_value}});
}
}
void record_exit_reson(std::string outputdir, int code, int plate_id, std::string error_message, sliced_info_t& sliced_info, std::map<std::string, std::string> key_values = std::map<std::string, std::string>())
{
#if defined(__linux__) || defined(__LINUX__)
@@ -1967,11 +1982,7 @@ int CLI::run(int argc, char **argv)
record_exit_reson(outfile_dir, CLI_INVALID_PRINTER_TECH, 0, cli_errors[CLI_INVALID_PRINTER_TECH], sliced_info);
flush_and_exit(CLI_INVALID_PRINTER_TECH);
}
if (!config_substitutions.substitutions.empty()) {
BOOST_LOG_TRIVIAL(info) << "Found legacy configuration values, substituted when loading " << file << ":\n";
for (const ConfigSubstitution &subst : config_substitutions.substitutions)
BOOST_LOG_TRIVIAL(info) << "\tkey = \"" << subst.opt_def->opt_key << "\"\t old_value = \"" << subst.old_value << "\tnew_value = \"" << subst.new_value->serialize() << "\"\n";
}
cli_report_config_substitutions(file, config_substitutions.substitutions, sliced_info);
// config is applied to m_print_config before the current m_config values.
config += std::move(m_print_config);
@@ -2184,7 +2195,7 @@ int CLI::run(int argc, char **argv)
return Slic3r::escape_strings_cstyle(keys);
};
auto load_config_file = [&resolve_preset](const std::string& file, DynamicPrintConfig& config, std::string& config_type,
auto load_config_file = [&resolve_preset, &sliced_info](const std::string& file, DynamicPrintConfig& config, std::string& config_type,
std::string& config_name, std::string& filament_id, std::string& config_from) {
if (! boost::filesystem::exists(file)) {
boost::nowide::cerr << __FUNCTION__<< ": can not find setting file: " << file << std::endl;
@@ -2242,9 +2253,7 @@ int CLI::run(int argc, char **argv)
config.normalize_fdm();
if (! config_substitutions.empty()) {
BOOST_LOG_TRIVIAL(info) << "Found legacy configuration values, substituted when loading " << file << ":\n";
for (const ConfigSubstitution &subst : config_substitutions)
BOOST_LOG_TRIVIAL(info) << "\tkey = \"" << subst.opt_def->opt_key << "\"\t old_value = \"" << subst.old_value << "\tnew_value = \"" << subst.new_value->serialize() << "\"\n";
cli_report_config_substitutions(file, config_substitutions, sliced_info);
}
else {
BOOST_LOG_TRIVIAL(info) << "no substitutions performed from file " << file << "\n";