From be94a6a0da165efecc1b3bd929b5c9de99a63e04 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Sat, 7 Nov 2026 12:42:01 +0800 Subject: [PATCH] Report why a local plugin install failed --- docs/HLSD/mcp-server.md | 2 +- src/slic3r/GUI/PluginsDialog.cpp | 34 +++++++++++------------ src/slic3r/plugin/PluginLoader.cpp | 9 ++++-- src/slic3r/plugin/PluginManager.cpp | 2 +- tests/slic3rutils/test_plugin_install.cpp | 19 +++++++++++++ 5 files changed, 43 insertions(+), 23 deletions(-) diff --git a/docs/HLSD/mcp-server.md b/docs/HLSD/mcp-server.md index 6e4a5b8af2..81f2aef073 100644 --- a/docs/HLSD/mcp-server.md +++ b/docs/HLSD/mcp-server.md @@ -1319,7 +1319,7 @@ turns a bad path into an Error result. | `export_stl_multi` | existing directory | `Plater::export_stl(..., multiple, dir)` | | `add_primitive_svg` | `.svg` | `GLGizmoSVG::create_volume(path, type)`: a new object, or a part of the selected one; a job | | `export_config` | existing directory | `ExportConfigsDialog(parent, dir)`: the dialog still opens, and its OK writes there | -| `install_local_plugin` | `.py`, `.whl` | `install_local_plugin_package(path, parent, message)`, the Plugins dialog's install: it still asks before replacing an installed plugin, in Orca's own "Overwrite Plugin" message dialog, which `dialog_respond` answers on every platform. Cancel makes the command an error saying that the plugin was not installed. A file that is not a `.py` or `.whl` is refused before that. A package that does not install is an Error. | +| `install_local_plugin` | `.py`, `.whl` | `install_local_plugin_package(path, parent, message)`, the Plugins dialog's install: it still asks before replacing an installed plugin, in Orca's own "Overwrite Plugin" message dialog, which `dialog_respond` answers on every platform. Cancel makes the command an error saying that the plugin was not installed. A file that is not a `.py` or `.whl` is refused before that. A package that fails inspection or installation is an Error whose message is "Plugin installation failed:" and the reason, such as a `.py` without a name in its PEP 723 `[tool.orcaslicer.plugin]` table | The six shape commands (`add_primitive_cube`, `_cylinder`, `_sphere`, `_cone`, `_disc`, `_torus`) take a `Text` param, the size the Primitive size dialog asks for (`"40 40 10"`, `"90 4"`), and then diff --git a/src/slic3r/GUI/PluginsDialog.cpp b/src/slic3r/GUI/PluginsDialog.cpp index b29e368be4..dd5a871405 100644 --- a/src/slic3r/GUI/PluginsDialog.cpp +++ b/src/slic3r/GUI/PluginsDialog.cpp @@ -562,23 +562,24 @@ bool install_local_plugin_package(const boost::filesystem::path& package_file, w return false; } + // The message is the package's own error, which says what to fix in it. Each reason arrives framed as a + // failed install ("Plugin installation failed: ...") by the code that made it, so none is framed here. + const auto failed = [&](const std::string& reason) { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Plugin package installation failed for " << package_file << " error=" << reason; + message = reason.empty() ? _L("Failed to install plugin package. See the log for details.") : from_u8(reason); + return false; + }; + PluginDescriptor plugin_descriptor; bool existing_installation = false; std::string error; try { - if (!PluginManager::instance().inspect_local_plugin_package(package_file, plugin_descriptor, existing_installation, error)) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Plugin package inspection failed for " << package_file << " error=" << error; - message = _L("Failed to install plugin package. See the log for details."); - return false; - } + if (!PluginManager::instance().inspect_local_plugin_package(package_file, plugin_descriptor, existing_installation, error)) + return failed(error); } catch (const std::exception& ex) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Plugin package inspection failed for " << package_file << " error=" << ex.what(); - message = _L("Failed to install plugin package. See the log for details."); - return false; + return failed(GUI::format(_u8L("Plugin installation failed: %1%"), ex.what())); } catch (...) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Plugin package inspection failed for " << package_file; - message = _L("Failed to install plugin package. See the log for details."); - return false; + return failed({}); } if (existing_installation) { @@ -615,9 +616,9 @@ bool install_local_plugin_package(const boost::filesystem::path& package_file, w try { ok = PluginManager::instance().install_plugin(package_file, error); } catch (const std::exception& ex) { - error = ex.what(); + error = GUI::format(_u8L("Plugin installation failed: %1%"), ex.what()); } catch (...) { - error = "Unknown error"; + error.clear(); } if (ok) { // Reflect the new package in discovery/cloud metadata without blocking the caller. @@ -635,11 +636,8 @@ bool install_local_plugin_package(const boost::filesystem::path& package_file, w error = std::move(state->error); } - if (!installed) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Plugin package installation failed for " << package_file << " error=" << error; - message = _L("Failed to install plugin package. See the log for details."); - return false; - } + if (!installed) + return failed(error); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Plugin package installed successfully from " << package_file; const wxString installed_name = from_u8(plugin_descriptor.name.empty() ? package_file.filename().string() : plugin_descriptor.name); diff --git a/src/slic3r/plugin/PluginLoader.cpp b/src/slic3r/plugin/PluginLoader.cpp index 756d535468..167d2705a7 100644 --- a/src/slic3r/plugin/PluginLoader.cpp +++ b/src/slic3r/plugin/PluginLoader.cpp @@ -629,8 +629,9 @@ bool inspect_local_plugin_package(const boost::filesystem::path& filepath, plugin_descriptor = PluginDescriptor{}; existing_installation = false; + // The inspection is the first step of an install, so its errors read as install_plugin's do. auto fail = [&error](const std::string& message) { - error = "Plugin package inspection failed: " + message; + error = GUI::format(_u8L("Plugin installation failed: %1%"), message); return false; }; @@ -638,7 +639,7 @@ bool inspect_local_plugin_package(const boost::filesystem::path& filepath, const fs::path source_path = canonical_or_absolute(filepath); if (!fs::exists(source_path, ec) || !fs::is_regular_file(source_path, ec)) - return fail("Plugin package is not a file: " + filepath.string()); + return fail(GUI::format(_u8L("Plugin package is not a file: %1%"), filepath.string())); std::string metadata_error; if (!read_local_plugin_package_metadata(source_path, plugin_descriptor, metadata_error)) @@ -727,7 +728,9 @@ bool install_plugin(const boost::filesystem::path& filepath, // read_wheel_plugin_metadata() already requires a Name and may legitimately leave the type // Unknown. if (ext == ".py" && plugin_descriptor.name.empty()) - return fail("Side-loaded .py plugin is missing required PEP 723 metadata: 'name' is required"); + // TRN %1% is the name of a TOML table, %2% an example of the comment block that holds it. + return fail(GUI::format(_u8L("The plugin has no name. Its PEP 723 block needs a %1% table with a name, as in:\n%2%"), + "[tool.orcaslicer.plugin]", "# /// script\n# [tool.orcaslicer.plugin]\n# name = \"My Plugin\"\n# ///")); } const fs::path final_dir = is_cloud_install ? plugin_root / cloud_uuid : local_plugin_install_dir(source_path); diff --git a/src/slic3r/plugin/PluginManager.cpp b/src/slic3r/plugin/PluginManager.cpp index 20dd206561..f5954eef5c 100644 --- a/src/slic3r/plugin/PluginManager.cpp +++ b/src/slic3r/plugin/PluginManager.cpp @@ -1559,7 +1559,7 @@ bool PluginManager::install_plugin(const boost::filesystem::path& filepath, Plug std::string wait_error; if (!wait_for_discovery(std::chrono::milliseconds::max(), wait_error)) { - error = wait_error.empty() ? "Plugin discovery is still running" : wait_error; + error = "Plugin discovery is still running"; if (!plugin_descriptor.plugin_key.empty()) set_plugin_error(plugin_descriptor.plugin_key, error); BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Plugin installation failed while waiting for discovery: " << error; diff --git a/tests/slic3rutils/test_plugin_install.cpp b/tests/slic3rutils/test_plugin_install.cpp index 04468f0ca4..15a7f34da6 100644 --- a/tests/slic3rutils/test_plugin_install.cpp +++ b/tests/slic3rutils/test_plugin_install.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #include #include +#include using namespace Slic3r; namespace fs = boost::filesystem; @@ -167,7 +169,24 @@ TEST_CASE("install_plugin rejects a side-loaded .py with no PEP 723 metadata", " const bool installed = plugin_loader::install_plugin(py, /*cloud_user_id=*/"", descriptor, error); REQUIRE_FALSE(installed); + // The error names the table the name goes in, so whoever reads it can fix the package. CHECK_THAT(error, Catch::Matchers::ContainsSubstring("PEP 723")); + CHECK_THAT(error, Catch::Matchers::ContainsSubstring("[tool.orcaslicer.plugin]")); +} + +TEST_CASE("a local install that fails inspection reports the reason once framed as a failed install", "[PluginInstall]") +{ + ScopedDataDir data_dir_guard("install-missing"); + + // The package is never found, so the install stops at its inspection, before any window opens. + wxString message; + const bool installed = GUI::install_local_plugin_package(data_dir_guard.dir / "missing.py", /*parent=*/nullptr, message); + + REQUIRE_FALSE(installed); + const std::string text(message.ToUTF8().data()); + CHECK_THAT(text, Catch::Matchers::StartsWith("Plugin installation failed: ")); + CHECK(text.find("Plugin installation failed", 1) == std::string::npos); + CHECK_THAT(text, Catch::Matchers::ContainsSubstring("missing.py")); } TEST_CASE("install_plugin accepts a side-loaded .py with complete PEP 723 metadata", "[PluginInstall]")