CrealityPrint: propagate start_print() errors to caller

Change start_print() from void to bool with a wxString& msg
out-parameter, matching the error handling pattern used by Duet,
MKS, ESP3D and Flashforge. On failure, the error message is now
reported to the user via error_fn instead of being silently
swallowed. Use BOOST_LOG_TRIVIAL for logging instead of std::cerr.

Signed-off-by: Igor Mammedov <niallain@gmail.com>
This commit is contained in:
Igor Mammedov
2026-04-21 19:48:39 +02:00
parent 376841e28e
commit e995541c25
2 changed files with 11 additions and 5 deletions

View File

@@ -137,7 +137,11 @@ bool CrealityPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn,
BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: File uploaded: HTTP %2%: %3%") % name % status % body;
if (upload_data.post_action == PrintHostPostUploadAction::StartPrint) {
start_print(safe_filename(upload_filename.string()));
wxString errormsg;
if (!start_print(errormsg, safe_filename(upload_filename.string()))) {
error_fn(std::move(errormsg));
res = false;
}
}
})
.on_error([&](std::string body, std::string error, unsigned status) {
@@ -182,7 +186,7 @@ std::string CrealityPrint::safe_filename(const std::string &filename) const
return safe_filename;
}
void CrealityPrint::start_print(const std::string &filename) const
bool CrealityPrint::start_print(wxString &msg, const std::string &filename) const
{
try {
std::string host = Http::get_host_from_url(m_host);
@@ -225,10 +229,12 @@ void CrealityPrint::start_print(const std::string &filename) const
ws.read(buffer);
ws.close(websocket::close_code::normal);
return true;
} catch(std::exception const& e) {
std::cerr << "Error: " << e.what() << std::endl;
BOOST_LOG_TRIVIAL(error) << "CrealityPrint: Error starting print: " << e.what();
msg = wxString::FromUTF8(e.what());
return false;
}
}
}

View File

@@ -41,7 +41,7 @@ private:
bool m_ssl_revoke_best_effort;
std::string make_url(const std::string& path) const;
void start_print(const std::string& path) const;
bool start_print(wxString& msg, const std::string& path) const;
std::string safe_filename(const std::string& filename) const;
};
} // namespace Slic3r