From 505b7c2ac63cec7d20db8303e873b2a28fe659d4 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Sat, 27 Jul 2024 13:46:57 +0200 Subject: [PATCH] bgcode: Propagate errors from valid_for_print MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a file fails the valid for print check not because it is still not downloaded, but because it is somehow broken, report it as such. This goes all the way to the GUI, instead of the „Downloading“ screen. BFW-5830. --- src/common/gcode/gcode_reader_binary.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/common/gcode/gcode_reader_binary.cpp b/src/common/gcode/gcode_reader_binary.cpp index 8c293dbfb6..91ff01c89f 100644 --- a/src/common/gcode/gcode_reader_binary.cpp +++ b/src/common/gcode/gcode_reader_binary.cpp @@ -629,6 +629,25 @@ bool PrusaPackGcodeReader::valid_for_print() { return IterateResult_t::Continue; }); + if (auto err = std::get_if(&res); err != nullptr) { + switch (*err) { + case Result_t::RESULT_EOF: + set_error(N_("File doesn't contain any print instructions")); + break; + case Result_t::RESULT_CORRUPT: + set_error(N_("File corrupt")); + break; + case Result_t::RESULT_ERROR: + set_error(N_("Unknown file error")); + break; + default: + // All the rest (OK, Timeout, out of range) don't prevent this + // file from being printable in the future, so don't set any + // error. + break; + } + } + return std::holds_alternative(res); }