Skip to main content

molframe_core/diagnostic/
registry.rs

1//! The diagnostic code registry.
2//!
3//! Declaring codes as data rather than as scattered string literals buys three
4//! things: a remedy is structurally required rather than remembered, the whole
5//! set can be enumerated for documentation, and a code's severity is decided in
6//! one place instead of at each site that raises it.
7//!
8//! Entries are declared in sorted order — errors before warnings, then by
9//! number — because lookup binary-searches this table. A test enforces it.
10
11use super::code::{Code, Entry, Kind, Severity};
12
13macro_rules! registry {
14    ($($name:ident = $kind:ident $number:literal, $severity:ident, $cause:literal, $remedy:literal;)*) => {
15        impl Code {
16            $(
17                #[doc = $cause]
18                pub const $name: Self = Self::new(Kind::$kind, $number);
19            )*
20        }
21
22        pub(super) static ENTRIES: &[Entry] = &[$(
23            Entry {
24                code: Code::new(Kind::$kind, $number),
25                severity: Severity::$severity,
26                cause: $cause,
27                remedy: $remedy,
28            },
29        )*];
30    };
31}
32
33registry! {
34    E1001 = Error 1001, Breaking,
35        "format could not be determined",
36        "pass the format explicitly, or give the file an extension the reader recognises";
37    E1101 = Error 1101, Breaking,
38        "unterminated quoted value",
39        "close the quote; a value containing a quote character must use the other quote style or a multi-line text field";
40    E1102 = Error 1102, Breaking,
41        "unterminated multi-line text field",
42        "close the field with a semicolon at the start of a line";
43    E1103 = Error 1103, Breaking,
44        "loop_ row count is not a multiple of the column count",
45        "count the values in the final row; an unquoted value containing a space parses as two values";
46    E1104 = Error 1104, Invalidating,
47        "duplicate tag within a category",
48        "remove the repeated tag; the two values cannot both be the value of one item";
49    E1105 = Error 1105, Breaking,
50        "value outside any category",
51        "precede the value with the tag it belongs to, or with a loop_ header";
52    E1106 = Error 1106, Breaking,
53        "missing data_ block header",
54        "add a data_ line before the first category; a file with no block cannot be addressed";
55    E1201 = Error 1201, Invalidating,
56        "malformed fixed-column record",
57        "check the record against its column layout; fields are positional, so one misplaced column shifts every field after it";
58    E1202 = Error 1202, Invalidating,
59        "unparseable numeric field",
60        "correct the field, or read in recover mode to keep the rest of the file";
61    E1203 = Error 1203, Invalidating,
62        "atom serial exceeds format capacity and is not hybrid-36",
63        "re-encode the serial in hybrid-36, or use a format without a five-column serial field";
64    E1401 = Error 1401, Breaking,
65        "declared length disagrees with the encoded payload",
66        "the file is truncated or corrupt; fetch it again";
67    E1402 = Error 1402, Breaking,
68        "unknown column encoding",
69        "the file uses an encoding this version does not implement; upgrade molframe";
70    E1403 = Error 1403, Breaking,
71        "codec chain type mismatch",
72        "the encoding chain is inconsistent with itself; report it to whatever wrote the file";
73    E1901 = Error 1901, Breaking,
74        "resource limit exceeded",
75        "raise the limit deliberately if the input is genuinely this large; the default guards against decompression bombs and absurd declared row counts";
76    E1902 = Error 1902, Breaking,
77        "source window exceeds the execution memory budget",
78        "reduce the requested window or deliberately raise the execution memory budget";
79    E1903 = Error 1903, Breaking,
80        "source window cannot be represented on this host",
81        "request a smaller window or use a host whose address space can represent it";
82    E1904 = Error 1904, Breaking,
83        "execution cancelled",
84        "start a new execution with an uncancelled context when the result is still needed";
85    E2001 = Error 2001, Invalidating,
86        "required category absent",
87        "add the category, or read with a strictness that tolerates its absence";
88    E2002 = Error 2002, Invalidating,
89        "required item absent",
90        "add the item; without it the affected rows cannot be interpreted";
91    E2003 = Error 2003, Strict,
92        "value outside the declared enumeration",
93        "use one of the enumerated values, or relax strictness to accept the file as deposited";
94    E2004 = Error 2004, Invalidating,
95        "value has the wrong type for its item",
96        "correct the value; a numeric item cannot hold text";
97    E2005 = Error 2005, Strict,
98        "parent-child relationship violated",
99        "add the missing parent row, or correct the child's reference";
100    E3001 = Error 3001, Invalidating,
101        "column length disagrees with the chunk length",
102        "report this as a molframe bug; a structure cannot be built this way from valid input";
103    E3002 = Error 3002, Invalidating,
104        "child range exceeds the child table",
105        "report this as a molframe bug";
106    E3003 = Error 3003, Invalidating,
107        "overlapping child ranges",
108        "report this as a molframe bug";
109    E3004 = Error 3004, Invalidating,
110        "atom belongs to no residue",
111        "report this as a molframe bug";
112    E3005 = Error 3005, Invalidating,
113        "chain references a nonexistent entity",
114        "check the entity identifiers the chains refer to";
115    E3006 = Error 3006, Invalidating,
116        "bond endpoint out of range",
117        "check the connectivity records; they name an atom the file does not contain";
118    E3007 = Error 3007, Invalidating,
119        "self-bond",
120        "remove the connectivity record bonding an atom to itself";
121    E3008 = Error 3008, Invalidating,
122        "non-finite coordinate without a validity mark",
123        "correct the coordinate, or mark the atom's position as unrecorded";
124    E3009 = Error 3009, Strict,
125        "occupancy outside the zero-to-one range",
126        "correct the occupancy; values outside the range make occupancy-weighted results meaningless";
127    E3010 = Error 3010, Invalidating,
128        "models share a coordinate set but not an atom count",
129        "the models differ in composition and must be held as a ragged ensemble rather than as frames";
130    E3011 = Error 3011, Invalidating,
131        "custom annotation length disagrees with the atom count",
132        "supply exactly one annotation row for every atom row";
133    E3012 = Error 3012, Invalidating,
134        "structures cannot share one merged model axis",
135        "merge structures with equal dense model counts, or keep unlike models as a ragged ensemble";
136    E3013 = Error 3013, Invalidating,
137        "custom annotation types disagree across structures",
138        "convert same-named annotation columns to one physical type before merging";
139    E3014 = Error 3014, Invalidating,
140        "domain extensions would be invalidated by a topology change",
141        "explicitly clear extensions before editing topology or merging structures";
142    E3015 = Error 3015, Invalidating,
143        "residue boundary is not defined by the deposited identifiers",
144        "repair the residue identifiers or explicitly select file-order boundary inference";
145    E3201 = Error 3201, Invalidating,
146        "bundled chemistry reference data is invalid",
147        "reinstall molframe from a verified distribution";
148    E3401 = Error 3401, Invalidating,
149        "topology and coordinate atom counts disagree",
150        "check that the coordinate source and the topology source describe the same system";
151    E4001 = Error 4001, Invalidating,
152        "selection syntax is invalid",
153        "correct the selection at the reported token";
154    E4002 = Error 4002, Invalidating,
155        "selection value is incompatible with its column",
156        "use a value of the column's declared type";
157    E4003 = Error 4003, Invalidating,
158        "selection requires data this structure does not carry",
159        "provide the required annotations or choose a selector available for this structure";
160    E4004 = Error 4004, Invalidating,
161        "unknown selection keyword",
162        "check the spelling against the keyword list; an annotation column can also be selected by its own name";
163    E4101 = Error 4101, Invalidating,
164        "atom count exceeds legacy format capacity",
165        "write mmCIF or BinaryCIF, or enable hybrid-36 serials explicitly";
166    E4102 = Error 4102, Invalidating,
167        "chain identifier cannot be represented in the target format",
168        "write mmCIF or BinaryCIF, or supply an explicit chain mapping";
169    E4103 = Error 4103, Invalidating,
170        "residue number exceeds legacy format capacity",
171        "write mmCIF or BinaryCIF, or enable hybrid-36 residue numbers explicitly";
172    E4104 = Error 4104, Invalidating,
173        "coordinate magnitude exceeds the target field width",
174        "translate the structure towards the origin, or write a format with wider coordinate fields";
175    E4105 = Error 4105, Invalidating,
176        "the target format cannot express a required category",
177        "write a format that models the data, or drop the category deliberately";
178    E5001 = Error 5001, Invalidating,
179        "superposition is undefined for fewer than three non-collinear atoms",
180        "widen the selection until it spans three dimensions";
181    E5002 = Error 5002, Invalidating,
182        "degenerate frame from collinear reference atoms",
183        "choose reference atoms that are not in a straight line";
184    E5003 = Error 5003, Invalidating,
185        "empty selection where atoms are required",
186        "check the selection against the structure; a keyword that matches nothing here may match elsewhere";
187    E5004 = Error 5004, Invalidating,
188        "periodic query without a unit cell",
189        "supply a cell, or ask for a non-periodic query";
190    E5005 = Error 5005, Invalidating,
191        "cutoff exceeds half the minimum box dimension under the minimum image convention",
192        "reduce the cutoff, or use a periodic mode that considers more than the nearest image";
193    E6001 = Error 6001, Invalidating,
194        "unqualified identifier while the policy requires explicit namespaces",
195        "qualify the selector, for instance auth_chain rather than chain";
196    E6002 = Error 6002, Invalidating,
197        "requested assembly does not exist",
198        "list the assemblies the entry defines and choose one of them";
199    E6003 = Error 6003, Invalidating,
200        "requested model does not exist",
201        "check the model count; models are addressed by position, not by deposited number";
202    E6004 = Error 6004, Invalidating,
203        "policy field combination is contradictory",
204        "reconcile the two fields; the analysis cannot honour both";
205    E6005 = Error 6005, Invalidating,
206        "verdict profile not found",
207        "list the registered profiles; profile names carry a version";
208    E6006 = Error 6006, Invalidating,
209        "requested chain does not exist",
210        "check the chain count or resolve the chain label before editing";
211    E6007 = Error 6007, Invalidating,
212        "identifier is empty",
213        "supply a non-empty identifier";
214    E6008 = Error 6008, Invalidating,
215        "a whole-ensemble coordinate edit requires shared topology",
216        "edit each ragged model snapshot independently";
217    E6009 = Error 6009, Invalidating,
218        "an atom selected for editing does not exist",
219        "restrict the selection to the structure atom range";
220    E6010 = Error 6010, Invalidating,
221        "assembly operator expression is malformed",
222        "use comma-separated identifiers and integer ranges, with each product factor in parentheses";
223    E6011 = Error 6011, Invalidating,
224        "assembly operator expression exceeds the instance limit",
225        "reduce the operator product or raise the explicit assembly limit";
226    E6012 = Error 6012, Invalidating,
227        "assembly category contains a malformed required value",
228        "correct the named assembly category item and row";
229    E6013 = Error 6013, Invalidating,
230        "assembly generator references an unknown definition",
231        "correct the referenced assembly, operator, or label-asym identifier";
232    E6014 = Error 6014, Invalidating,
233        "non-crystallographic symmetry operator is malformed",
234        "correct the NCS identifier, given/generate code, matrix, or translation vector";
235    E6015 = Error 6015, Invalidating,
236        "crystallographic symmetry metadata or algebraic operation is malformed",
237        "correct the space-group number, operation identifier, or fractional xyz expression";
238    E6016 = Error 6016, Invalidating,
239        "crystal neighbour search configuration is incomplete or invalid",
240        "supply explicit symmetry operators, a valid model, and a positive finite cutoff";
241    E6017 = Error 6017, Invalidating,
242        "crystal neighbour search exceeds its candidate-image limit",
243        "reduce the cutoff or raise the explicit search limit after reviewing the expected cost";
244    E6018 = Error 6018, Invalidating,
245        "space-group setting is unknown or the bundled catalogue is invalid",
246        "supply a valid Hall symbol or International Tables number, or reinstall molframe";
247    E7901 = Error 7901, Invalidating,
248        "output could not be written",
249        "check the destination, permissions and available storage, then retry";
250    E9001 = Error 9001, Breaking,
251        "internal invariant violated",
252        "report this as a molframe bug with the input that produced it; no input should be able to cause this";
253    W1001 = Warning 1001, Loose,
254        "trailing content after the final block",
255        "remove the trailing content, or ignore this if the file is deliberately concatenated";
256    W1002 = Warning 1002, Info,
257        "non-standard whitespace or line ending",
258        "normalise the line endings if the file is meant to be portable";
259    W1901 = Warning 1901, Info,
260        "further findings were suppressed",
261        "the retained findings describe the problem; raise the diagnostic ceiling only if you need every occurrence rather than every distinct cause";
262    W2001 = Warning 2001, Info,
263        "unknown category retained but not interpreted",
264        "no action needed; the category survives a preserving write untouched";
265    W2002 = Warning 2002, Info,
266        "unknown item retained but not interpreted",
267        "no action needed; the item survives a preserving write untouched";
268    W2003 = Warning 2003, Loose,
269        "deprecated item used",
270        "migrate to the replacement item named in the dictionary";
271    W3011 = Warning 3011, Info,
272        "residue boundary was inferred from file order by explicit policy",
273        "check the residue identifiers in this region; consecutive residues carry annotations that do not distinguish them";
274    W3012 = Warning 3012, Loose,
275        "an alternate location carries a different component identity",
276        "no action needed; this is one residue modelled with two chemical identities, and both are retained";
277    W3201 = Warning 3201, Loose,
278        "component not found in any chemical component provider",
279        "supply a provider that knows this component if its expected atoms or bonds matter";
280    W3202 = Warning 3202, Strict,
281        "observed atoms are inconsistent with the component definition; file connectivity was used",
282        "check the component's atom names against its definition";
283    W3203 = Warning 3203, Loose,
284        "element inferred from the atom name",
285        "declare the element explicitly; the name-based rule is a convention that files are free to violate";
286    W3204 = Warning 3204, Loose,
287        "unusual valence",
288        "check the connectivity and formal charge of the atom named";
289    W3205 = Warning 3205, Strict,
290        "chirality disagrees with the component definition",
291        "check the geometry of the centre named; this is often a genuine modelling error";
292    W3301 = Warning 3301, Info,
293        "atoms expected by the component definition are absent from the model",
294        "no action needed; the shortfall is reported as coverage rather than hidden";
295    W3302 = Warning 3302, Loose,
296        "chain break detected within a polymer",
297        "no action needed; the gap is unmodelled density and is reported rather than bridged";
298    W4001 = Warning 4001, Loose,
299        "unparenthesised mix of and and or",
300        "parenthesise the expression; and binds more tightly than or, which may not be what was meant";
301    W4002 = Warning 4002, Loose,
302        "float equality comparison",
303        "compare against a range instead; exact equality on a measured quantity rarely matches";
304    W4003 = Warning 4003, Loose,
305        "selection symbol not present in this structure",
306        "check the spelling; the selection is valid but matches nothing here";
307    W4101 = Warning 4101, Strict,
308        "metadata dropped by the target format",
309        "write a format that models the metadata if it matters";
310    W5001 = Warning 5001, Info,
311        "neighbour list rebuilt more often than expected",
312        "increase the skin distance to trade memory for rebuild frequency";
313    W5002 = Warning 5002, Info,
314        "distance matrix requested for a large selection",
315        "use a neighbour query instead; a full matrix grows with the square of the selection";
316    W6001 = Warning 6001, Strict,
317        "per-atom highest occupancy may produce a conformation that was never modelled",
318        "prefer a conformer-consistent altloc policy unless per-atom selection is genuinely intended";
319    W6002 = Warning 6002, Info,
320        "assembly generated multiple instances of a chain",
321        "no action needed; instances carry their own identifiers and are distinguishable";
322    W6003 = Warning 6003, Strict,
323        "analysis returned an indeterminate result",
324        "read the assumptions and coverage; no defensible single answer exists under this policy";
325    W6004 = Warning 6004, Info,
326        "a defaulted policy field materially affects this result",
327        "set the field explicitly so the choice is recorded as yours rather than inherited";
328}
329
330#[cfg(test)]
331#[path = "registry_tests.rs"]
332mod tests;