mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-18 22:42:37 +00:00
CAD recipe v2: legible version-mismatch errors, refuse old files cleanly
Port of snaporca 04c3d579a7. Bump SNAPORCA_CAD_RECIPE_VERSION 1 -> 2; deserialize_recipe sets a user-facing error distinguishing too-new / too-old / corrupt instead of a silent bare false. No per-version migration by design. Golden fixture regenerated at v2 (v1 retired), field-value reorder tripwire unchanged. Fork adjustment: Catch2 v3 string matcher ContainsSubstring (not v2's Contains) in the two new version-mismatch tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BVzKmX6Y1aEteit1HTXG4Q
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
d04b02cd0e
commit
8edc12c8f1
@@ -1775,18 +1775,35 @@ std::string CadDocument::serialize_recipe() const
|
||||
|
||||
bool CadDocument::deserialize_recipe(const std::string& blob)
|
||||
{
|
||||
error.clear();
|
||||
try {
|
||||
std::istringstream iss(blob);
|
||||
cereal::BinaryInputArchive ar(iss);
|
||||
uint32_t v;
|
||||
ar(v);
|
||||
if (v > SNAPORCA_CAD_RECIPE_VERSION)
|
||||
if (v > SNAPORCA_CAD_RECIPE_VERSION) {
|
||||
error = "saved with a newer version of SnapOrca CAD (format v"
|
||||
+ std::to_string(v) + ", this build reads up to v"
|
||||
+ std::to_string(SNAPORCA_CAD_RECIPE_VERSION) + ")";
|
||||
return false;
|
||||
}
|
||||
if (v < SNAPORCA_CAD_RECIPE_VERSION) {
|
||||
error = "saved with an older version of SnapOrca CAD (format v"
|
||||
+ std::to_string(v) + "); this project cannot be opened by this build";
|
||||
return false;
|
||||
}
|
||||
ar(features);
|
||||
return recompute();
|
||||
} catch (const Standard_Failure&) {
|
||||
} catch (const Standard_Failure& e) {
|
||||
const char* what = e.GetMessageString();
|
||||
error = std::string("CAD data could not be read")
|
||||
+ (what && *what ? ": " + std::string(what) : "");
|
||||
return false;
|
||||
} catch (const std::exception& e) {
|
||||
error = std::string("CAD data could not be read: ") + e.what();
|
||||
return false;
|
||||
} catch (...) {
|
||||
error = "CAD data could not be read";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,7 +356,11 @@ public:
|
||||
void clear();
|
||||
bool recompute(); // replay features -> body + display_mesh; false on error
|
||||
|
||||
static constexpr uint32_t SNAPORCA_CAD_RECIPE_VERSION = 1;
|
||||
// CadRecipe serialization contract:
|
||||
// - bump this whenever CadFeature::save/load gains or loses a field
|
||||
// - v1 blobs are deliberately not loadable; there is no migration path by design
|
||||
// - append fields ONLY at the end of save/load, never reorder (golden fixture enforces this)
|
||||
static constexpr uint32_t SNAPORCA_CAD_RECIPE_VERSION = 2;
|
||||
std::string serialize_recipe() const;
|
||||
bool deserialize_recipe(const std::string& blob);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user