diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index ba2cbc1fcd..abf56776d1 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -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 key_values = std::map()) { #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"; diff --git a/tests/cli/test_cli_strict.sh b/tests/cli/test_cli_strict.sh index 6051511f23..67ad8027c9 100644 --- a/tests/cli/test_cli_strict.sh +++ b/tests/cli/test_cli_strict.sh @@ -6,6 +6,9 @@ # --strict it also fails the run with CLI_SLICING_ERROR. --strict with --no-check is rejected up # front, because --no-check skips that check. # +# A preset value the config parser cannot accept is replaced with the option's default and +# reported as a "config_value_substituted" warning. --strict does not escalate that one. +# # usage: test_cli_strict.sh set -u @@ -44,9 +47,10 @@ cat > "$WORK/process.json" <<'EOF' } EOF -# A 40x40mm cap on an 8x8mm stem: the cap reaches ~22mm past the stem, beyond the 6mm -# cantilever limit of PrintObject::is_support_necessary(). -"$PY" - "$WORK/capital.stl" <<'EOF' +# capital.stl is a 40x40mm cap on an 8x8mm stem: the cap reaches ~22mm past the stem, beyond +# the 6mm cantilever limit of PrintObject::is_support_necessary(). cube.stl has no overhang at +# all, so it slices without raising the warning. +"$PY" - "$WORK/capital.stl" "$WORK/cube.stl" <<'EOF' import sys def box(x0, y0, z0, x1, y1, z1): @@ -56,25 +60,46 @@ def box(x0, y0, z0, x1, y1, z1): yield v[a], v[b], v[c] yield v[a], v[c], v[d] -with open(sys.argv[1], "w") as f: - f.write("solid capital\n") - for tri in (*box(16, 16, 0, 24, 24, 13), *box(0, 0, 12, 40, 40, 14)): - f.write("facet normal 0 0 0\nouter loop\n") - for p in tri: - f.write("vertex %g %g %g\n" % p) - f.write("endloop\nendfacet\n") - f.write("endsolid capital\n") +def write_stl(path, name, triangles): + with open(path, "w") as f: + f.write("solid %s\n" % name) + for tri in triangles: + f.write("facet normal 0 0 0\nouter loop\n") + for p in tri: + f.write("vertex %g %g %g\n" % p) + f.write("endloop\nendfacet\n") + f.write("endsolid %s\n" % name) + +write_stl(sys.argv[1], "capital", (*box(16, 16, 0, 24, 24, 13), *box(0, 0, 12, 40, 40, 14))) +write_stl(sys.argv[2], "cube", box(10, 10, 0, 30, 30, 20)) +EOF + +# The same process, with an ironing_type the enum does not define. The parser cannot accept +# it and falls back to the option's default, "no ironing". +cat > "$WORK/process_bad_enum.json" <<'EOF' +{ + "type": "process", + "from": "User", + "name": "CLI strict test process, invalid ironing_type", + "enable_support": "0", + "enforce_support_layers": "0", + "ironing_type": "every other layer" +} EOF fails=0 fail() { echo "FAIL: $*"; fails=$((fails + 1)); } +# What run() slices; a case that needs something else assigns to them and restores after. +PROCESS="$WORK/process.json" +MODEL="$WORK/capital.stl" + # run [option...]: slice into $WORK/, keeping the log and the shell status there. run() { local out="$WORK/$1"; shift mkdir -p "$out" - timeout 300 "$BIN" --datadir "$WORK/datadir" --load-settings "$WORK/machine.json;$WORK/process.json" \ - "$@" --slice 0 --outputdir "$out" "$WORK/capital.stl" > "$out/log" 2>&1 + timeout 300 "$BIN" --datadir "$WORK/datadir" --load-settings "$WORK/machine.json;$PROCESS" \ + "$@" --slice 0 --outputdir "$out" "$MODEL" > "$out/log" 2>&1 echo $? > "$out/status" } @@ -123,6 +148,30 @@ sys.exit(1 if errors else 0) EOF } +# expect_substitution +expect_substitution() { + "$PY" - "$WORK/$1/result.json" "$2" "$3" "$4" <<'EOF' || fail "$1: result.json" +import json, sys + +path, key, old_value, new_value = sys.argv[1:5] +try: + with open(path) as f: + result = json.load(f) +except (OSError, ValueError) as e: + sys.exit("cannot read %s: %s" % (path, e)) + +warnings = result.get("warnings") +if not isinstance(warnings, list): + sys.exit("warnings %r is not a list" % (warnings,)) +for w in warnings: + if isinstance(w, dict) and w.get("class") == "config_value_substituted" and w.get("key") == key: + if w.get("old_value") == old_value and w.get("new_value") == new_value: + sys.exit(0) + sys.exit("%r, want old_value %r and new_value %r" % (w, old_value, new_value)) +sys.exit("no config_value_substituted warning for %r in %r" % (key, warnings)) +EOF +} + echo "== without --strict the warning is listed and the slice succeeds" run plain expect_status plain $CLI_SUCCESS @@ -143,6 +192,19 @@ expect_gcode conflict no grep -q -- "--strict cannot be combined with --no-check" "$WORK/conflict/log" \ || fail "conflict: error message missing" +echo "== a value the parser cannot accept is reported, and --strict does not escalate it" +PROCESS="$WORK/process_bad_enum.json" +MODEL="$WORK/cube.stl" +run substituted --strict +PROCESS="$WORK/process.json" +MODEL="$WORK/capital.stl" +expect_status substituted $CLI_SUCCESS +expect_result substituted $CLI_SUCCESS true none +expect_substitution substituted ironing_type "every other layer" "no ironing" +expect_gcode substituted yes +grep -q "ironing_type is not valid" "$WORK/substituted/log" \ + || fail "substituted: console warning missing" + if [ "$fails" -ne 0 ]; then for log in "$WORK"/*/log; do echo "--- $log"