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    E4005 = Error 4005, Invalidating,
164        "named query is not defined",
165        "define the name before referring to it, or check its spelling";
166    E4006 = Error 4006, Invalidating,
167        "named query definitions refer to each other in a cycle",
168        "break the cycle so that every name eventually resolves to atoms rather than to itself";
169    E4007 = Error 4007, Invalidating,
170        "named query nesting is too deep",
171        "flatten the chain of definitions; each name may refer to at most a bounded depth of other names";
172    E4101 = Error 4101, Invalidating,
173        "atom count exceeds legacy format capacity",
174        "write mmCIF or BinaryCIF, or enable hybrid-36 serials explicitly";
175    E4102 = Error 4102, Invalidating,
176        "chain identifier cannot be represented in the target format",
177        "write mmCIF or BinaryCIF, or supply an explicit chain mapping";
178    E4103 = Error 4103, Invalidating,
179        "residue number exceeds legacy format capacity",
180        "write mmCIF or BinaryCIF, or enable hybrid-36 residue numbers explicitly";
181    E4104 = Error 4104, Invalidating,
182        "coordinate magnitude exceeds the target field width",
183        "translate the structure towards the origin, or write a format with wider coordinate fields";
184    E4105 = Error 4105, Invalidating,
185        "the target format cannot express a required category",
186        "write a format that models the data, or drop the category deliberately";
187    E5001 = Error 5001, Invalidating,
188        "superposition is undefined for fewer than three non-collinear atoms",
189        "widen the selection until it spans three dimensions";
190    E5002 = Error 5002, Invalidating,
191        "degenerate frame from collinear reference atoms",
192        "choose reference atoms that are not in a straight line";
193    E5003 = Error 5003, Invalidating,
194        "empty selection where atoms are required",
195        "check the selection against the structure; a keyword that matches nothing here may match elsewhere";
196    E5004 = Error 5004, Invalidating,
197        "periodic query without a unit cell",
198        "supply a cell, or ask for a non-periodic query";
199    E5005 = Error 5005, Invalidating,
200        "cutoff exceeds half the minimum box dimension under the minimum image convention",
201        "reduce the cutoff, or use a periodic mode that considers more than the nearest image";
202    E6001 = Error 6001, Invalidating,
203        "unqualified identifier while the policy requires explicit namespaces",
204        "qualify the selector, for instance auth_chain rather than chain";
205    E6002 = Error 6002, Invalidating,
206        "requested assembly does not exist",
207        "list the assemblies the entry defines and choose one of them";
208    E6003 = Error 6003, Invalidating,
209        "requested model does not exist",
210        "check the model count; models are addressed by position, not by deposited number";
211    E6004 = Error 6004, Invalidating,
212        "policy field combination is contradictory",
213        "reconcile the two fields; the analysis cannot honour both";
214    E6005 = Error 6005, Invalidating,
215        "verdict profile not found",
216        "list the registered profiles; profile names carry a version";
217    E6006 = Error 6006, Invalidating,
218        "requested chain does not exist",
219        "check the chain count or resolve the chain label before editing";
220    E6007 = Error 6007, Invalidating,
221        "identifier is empty",
222        "supply a non-empty identifier";
223    E6008 = Error 6008, Invalidating,
224        "a whole-ensemble coordinate edit requires shared topology",
225        "edit each ragged model snapshot independently";
226    E6009 = Error 6009, Invalidating,
227        "an atom selected for editing does not exist",
228        "restrict the selection to the structure atom range";
229    E6010 = Error 6010, Invalidating,
230        "assembly operator expression is malformed",
231        "use comma-separated identifiers and integer ranges, with each product factor in parentheses";
232    E6011 = Error 6011, Invalidating,
233        "assembly operator expression exceeds the instance limit",
234        "reduce the operator product or raise the explicit assembly limit";
235    E6012 = Error 6012, Invalidating,
236        "assembly category contains a malformed required value",
237        "correct the named assembly category item and row";
238    E6013 = Error 6013, Invalidating,
239        "assembly generator references an unknown definition",
240        "correct the referenced assembly, operator, or label-asym identifier";
241    E6014 = Error 6014, Invalidating,
242        "non-crystallographic symmetry operator is malformed",
243        "correct the NCS identifier, given/generate code, matrix, or translation vector";
244    E6015 = Error 6015, Invalidating,
245        "crystallographic symmetry metadata or algebraic operation is malformed",
246        "correct the space-group number, operation identifier, or fractional xyz expression";
247    E6016 = Error 6016, Invalidating,
248        "crystal neighbour search configuration is incomplete or invalid",
249        "supply explicit symmetry operators, a valid model, and a positive finite cutoff";
250    E6017 = Error 6017, Invalidating,
251        "crystal neighbour search exceeds its candidate-image limit",
252        "reduce the cutoff or raise the explicit search limit after reviewing the expected cost";
253    E6018 = Error 6018, Invalidating,
254        "space-group setting is unknown or the bundled catalogue is invalid",
255        "supply a valid Hall symbol or International Tables number, or reinstall molframe";
256    E7901 = Error 7901, Invalidating,
257        "output could not be written",
258        "check the destination, permissions and available storage, then retry";
259    E9001 = Error 9001, Breaking,
260        "internal invariant violated",
261        "report this as a molframe bug with the input that produced it; no input should be able to cause this";
262    W1001 = Warning 1001, Loose,
263        "trailing content after the final block",
264        "remove the trailing content, or ignore this if the file is deliberately concatenated";
265    W1002 = Warning 1002, Info,
266        "non-standard whitespace or line ending",
267        "normalise the line endings if the file is meant to be portable";
268    W1901 = Warning 1901, Info,
269        "further findings were suppressed",
270        "the retained findings describe the problem; raise the diagnostic ceiling only if you need every occurrence rather than every distinct cause";
271    W2001 = Warning 2001, Info,
272        "unknown category retained but not interpreted",
273        "no action needed; the category survives a preserving write untouched";
274    W2002 = Warning 2002, Info,
275        "unknown item retained but not interpreted",
276        "no action needed; the item survives a preserving write untouched";
277    W2003 = Warning 2003, Loose,
278        "deprecated item used",
279        "migrate to the replacement item named in the dictionary";
280    W3011 = Warning 3011, Info,
281        "residue boundary was inferred from file order by explicit policy",
282        "check the residue identifiers in this region; consecutive residues carry annotations that do not distinguish them";
283    W3012 = Warning 3012, Loose,
284        "an alternate location carries a different component identity",
285        "no action needed; this is one residue modelled with two chemical identities, and both are retained";
286    W3201 = Warning 3201, Loose,
287        "component not found in any chemical component provider",
288        "supply a provider that knows this component if its expected atoms or bonds matter";
289    W3202 = Warning 3202, Strict,
290        "observed atoms are inconsistent with the component definition; file connectivity was used",
291        "check the component's atom names against its definition";
292    W3203 = Warning 3203, Loose,
293        "element inferred from the atom name",
294        "declare the element explicitly; the name-based rule is a convention that files are free to violate";
295    W3204 = Warning 3204, Loose,
296        "unusual valence",
297        "check the connectivity and formal charge of the atom named";
298    W3205 = Warning 3205, Strict,
299        "chirality disagrees with the component definition",
300        "check the geometry of the centre named; this is often a genuine modelling error";
301    W3301 = Warning 3301, Info,
302        "atoms expected by the component definition are absent from the model",
303        "no action needed; the shortfall is reported as coverage rather than hidden";
304    W3302 = Warning 3302, Loose,
305        "chain break detected within a polymer",
306        "no action needed; the gap is unmodelled density and is reported rather than bridged";
307    W4001 = Warning 4001, Loose,
308        "unparenthesised mix of and and or",
309        "parenthesise the expression; and binds more tightly than or, which may not be what was meant";
310    W4002 = Warning 4002, Loose,
311        "float equality comparison",
312        "compare against a range instead; exact equality on a measured quantity rarely matches";
313    W4003 = Warning 4003, Loose,
314        "selection symbol not present in this structure",
315        "check the spelling; the selection is valid but matches nothing here";
316    W4101 = Warning 4101, Strict,
317        "metadata dropped by the target format",
318        "write a format that models the metadata if it matters";
319    W5001 = Warning 5001, Info,
320        "neighbour list rebuilt more often than expected",
321        "increase the skin distance to trade memory for rebuild frequency";
322    W5002 = Warning 5002, Info,
323        "distance matrix requested for a large selection",
324        "use a neighbour query instead; a full matrix grows with the square of the selection";
325    W6001 = Warning 6001, Strict,
326        "per-atom highest occupancy may produce a conformation that was never modelled",
327        "prefer a conformer-consistent altloc policy unless per-atom selection is genuinely intended";
328    W6002 = Warning 6002, Info,
329        "assembly generated multiple instances of a chain",
330        "no action needed; instances carry their own identifiers and are distinguishable";
331    W6003 = Warning 6003, Strict,
332        "analysis returned an indeterminate result",
333        "read the assumptions and coverage; no defensible single answer exists under this policy";
334    W6004 = Warning 6004, Info,
335        "a defaulted policy field materially affects this result",
336        "set the field explicitly so the choice is recorded as yours rather than inherited";
337}
338
339#[cfg(test)]
340#[path = "registry_tests.rs"]
341mod tests;