Skip to content
Snippets Groups Projects
Commit 4df0bc37 authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

Merge branch '320-opmdocument-check-file-version-during-deserialization' into 'main'

feat: :sparkles: Issue warning if read OPM file version differs from programm version.

Closes #320

See merge request !212
parents 89408c98 3d5eca6f
No related branches found
No related tags found
1 merge request!212feat: :sparkles: Issue warning if read OPM file version differs from programm version.
Pipeline #13812 failed
......@@ -5,6 +5,7 @@ use crate::{
optic_node::OpticNode,
SceneryResources,
};
use log::warn;
use serde::{Deserialize, Serialize};
use std::{
cell::RefCell,
......@@ -57,6 +58,15 @@ impl OpmDocument {
})?;
let mut document: Self = serde_yaml::from_str(&contents)
.map_err(|e| OpossumError::OpmDocument(format!("parsing of model failed: {e}")))?;
if document.opm_file_version != env!("OPM_FILE_VERSION") {
warn!("OPM file version does not match the used OPOSSUM version.");
warn!(
"read version '{}' <-> program file version '{}'",
document.opm_file_version,
env!("OPM_FILE_VERSION")
);
warn!("This file might haven been written by an older or newer version of OPOSSUM. The model import might not be correct.");
}
document.scenery.after_deserialization_hook()?;
document
.scenery
......@@ -74,7 +84,7 @@ impl OpmDocument {
/// - it cannot write into the file (e.g. no space).
pub fn save_to_file(&self, path: &Path) -> OpmResult<()> {
let serialized = serde_yaml::to_string(&self).map_err(|e| {
OpossumError::OpticScenery(format!("deserialization of OpmDocument failed: {e}"))
OpossumError::OpticScenery(format!("serialization of OpmDocument failed: {e}"))
})?;
let mut output = File::create(path).map_err(|e| {
OpossumError::OpticScenery(format!(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment