mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-22 16:32:40 +00:00
# Description <!-- > Please provide a summary of the changes made in this PR. Include details such as: > * What issue does this PR address or fix? > * What new features or enhancements does this PR introduce? > * Are there any breaking changes or dependencies that need to be considered? --> A Python printer agent plugin could take the host down, and one of its operations could never report its result. This PR fixes both in `PrinterAgentPluginCapabilityTrampoline.hpp`. ## Changes ### A faulty printer agent no longer throws into the GUI `IPrinterAgent` reports failure through return values, and none of its callers catch. A Python `raise`, a missing override or a wrongly typed return from a printer agent plugin therefore escaped the trampoline as a C++ exception. Every trampoline operation now catches, logs `Printer agent plugin '<key>': <operation> failed: <error>`, and answers with what `NetworkAgent` returns when no printer agent is set. `BBLPrinterAgent` returns the same values when the Bambu plug-in is unavailable: - `-1` for every `int` status code - `false` for `start_discovery` and `fetch_filament_info` - `""` for `get_user_selected_machine` - an empty `AgentInfo` for `get_agent_info` (registration already rejects an empty agent ID) - `FilamentSyncMode::none` for `get_filament_sync_mode` `ORCA_PY_AGENT_OVERRIDE(ret, name, ...)` derives the fallback from the return type through `printer_agent_failure<ret>()`, so the call sites carry no fallback values of their own. An exception is the safety net for plugin bugs, not an error channel. A plugin reports an expected failure by returning a code, as the Bambu plug-in does. A raise is logged as a failure and collapses to the generic `-1`, so the GUI shows the generic message instead of the specific one (`-18` cancelled, `-4020` FTP upload failed, …). ### `bind_detect` results now reach the host `detect` is an out-parameter (`detectResult&`). pybind11 casts a reference argument to an override with a copy, so a plugin that filled in `detect` wrote to a throwaway object and the host always saw an empty `detectResult`. It is now passed so that Python edits the caller's struct. Plugins see the same `DetectResult` argument as before. ## TODO - Expose the `BAMBU_NETWORK_*` return codes to Python (the `orca.printer_agent` binding and the generated stub from `scripts/generate_orca_python_stubs.py`). Plugins can already return them, but only as hard-coded numbers. # Screenshots/Recordings/Graphs <!-- > Please attach relevant screenshots to showcase the UI changes. > Please attach images that can help explain the changes. --> ## Tests <!-- > Please describe the tests that you have conducted to verify the changes made in this PR. --> - New `tests/slic3rutils/test_plugin_printer_agent.cpp`: an agent whose operations raise, one that omits them, and one that returns the wrong type all answer like a missing agent, and the interpreter stays usable. A working agent's answers reach the host unchanged, including `request_bind_ticket`'s out-param and the fields a plugin writes into `bind_detect`'s `detect`. - The `bind_detect` check failed before the fix (`"" == "192.168.0.2"`) and passes after. - `slic3rutils` passes under `ctest` (144/144); full Release build clean on Linux. - End to end on Linux with a test plugin whose chosen operations raise (`start_discovery`, `get_filament_sync_mode`, `disconnect_printer`): selecting the plugin's agent in the printer preset and switching back logged each raise as a `Printer agent plugin '…': <operation> failed` line, and the app kept running and closed cleanly (exit 0). Without the guard, the first raise (`start_discovery`, on selecting the agent) ended the app with `Uncaught exception` and SIGABRT (exit 134); that run used a build whose printer-agent files are identical to `main`. <!-- > A guide for users on how to download the artifacts from this PR. --> [How to Download Pull Requests Artifacts for Testing](https://www.orcaslicer.com/wiki/how_to_download_pr_artifacts)
OrcaSlicer tests
Building, running and writing tests is documented on the wiki, under How to Test.
Two files here rather than there, because coding agents only read what is in the repository: