Skip to content

Commit 3f4a22b

Browse files
committed
add version check for report.conf
1 parent 499cea9 commit 3f4a22b

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

src/coreneuron/io/reports/report_configuration_parser.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,61 @@
2525

2626
namespace coreneuron {
2727

28+
void check_version(const std::string& raw, const int expected_major, const int expected_minor, const std::string& file_name) {
29+
// Must start with 'v'
30+
if (raw.empty() || raw[0] != 'v') {
31+
throw std::runtime_error(
32+
"Invalid major version in: \"" + raw + "\". \"" + file_name + "\" may be missing a version line. "
33+
"Expected format: v<major>[.<minor>], e.g., v1.3 or v2"
34+
);
35+
}
36+
37+
std::string s = raw.substr(1); // strip 'v'
38+
int major = 0;
39+
int minor = 0;
40+
41+
size_t dot = s.find('.');
42+
std::string major_str = (dot == std::string::npos) ? s : s.substr(0, dot);
43+
std::string minor_str = (dot == std::string::npos) ? "" : s.substr(dot + 1);
44+
45+
// Parse major
46+
try {
47+
major = std::stoi(major_str);
48+
} catch (...) {
49+
throw std::runtime_error(
50+
"Invalid major version in: \"" + raw + "\". \"" + file_name + "\" may be missing a version line. "
51+
"Expected format: v<major>[.<minor>], e.g., v1.3 or v2"
52+
);
53+
}
54+
55+
// Major check
56+
if (major != expected_major) {
57+
throw std::runtime_error(
58+
"Expected version \"v" + std::to_string(expected_major) +
59+
"\", got \"" + raw + "\". Probably a version mismatch between neurodamus and neuron."
60+
);
61+
}
62+
63+
// Parse minor if present
64+
if (!minor_str.empty()) {
65+
try {
66+
minor = std::stoi(minor_str);
67+
} catch (...) {
68+
throw std::runtime_error("Invalid minor version in: " + raw);
69+
}
70+
71+
if (minor > expected_minor) {
72+
std::cerr << "Warning: version minor " << minor
73+
<< " is above expected " << expected_minor
74+
<< ". Continuing.\n";
75+
} else if (minor < expected_minor) {
76+
throw std::runtime_error(
77+
"Minor version below expected: probably a version mismatch between neurodamus and neuron. Got \"" +
78+
raw + "\""
79+
);
80+
}
81+
}
82+
}
2883

2984
/*
3085
* Split filter comma separated strings ("mech.var_name") into mech_name and var_name
@@ -68,6 +123,12 @@ std::vector<ReportConfiguration> create_report_configurations(const std::string&
68123
int target;
69124
std::ifstream report_conf(conf_file);
70125

126+
std::string version;
127+
report_conf >> version;
128+
129+
// coreneuron is compatible with: report.conf v1.x or v1
130+
check_version(version, 1, 0, "report.conf");
131+
71132
int num_reports = 0;
72133
report_conf >> num_reports;
73134
std::vector<ReportConfiguration> reports(num_reports);

0 commit comments

Comments
 (0)