zu_common/gqlstatus.rs
1//! GQLSTATUS: the ISO/IEC 39075:2024 condition codes and the diagnostic
2//! record that carries one back to a caller (Spec/2064g/gql/plan/07).
3//!
4//! Every condition GQL defines is a five-character code, a two-character
5//! class and a three-character subclass, and the standard fixes both the
6//! code and the natural-language name that goes with it. Those names are
7//! not ours to invent, so the table in `generated.rs` is machine-written
8//! from `artifacts/gql-conditions.xml`, the digital artifact published
9//! alongside the standard. `tests/gqlstatus_table.rs` regenerates it and
10//! fails on drift.
11//!
12//! A [`GqlStatus`] is an index into that table, so it is two bytes, it is
13//! `Copy`, and a code that is not in the standard cannot be constructed.
14//! That last property is the point: an engine that answers with a code it
15//! made up has not raised a condition, it has printed a string.
16//!
17//! The conformance denominator is the 68 subclass rows. The table also
18//! carries one row per class, the class code followed by `000`, because
19//! that is a GQLSTATUS value too and it is the one a statement reports
20//! when nothing in particular happened: `00000 successful completion`.
21//! The artifact only writes those rows out for the four classes that
22//! have no subclasses, so the generator synthesises the other eight. That
23//! is why the totals here are 80 and 68 rather than one number.
24
25mod generated;
26
27use std::fmt;
28
29use generated::CONDITIONS;
30pub use generated::codes;
31
32/// What a condition means for the statement that raised it, taken from
33/// the class category letter in the artifact.
34#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
35pub enum Severity {
36 /// `S`: the statement succeeded.
37 Success,
38 /// `N`: the statement succeeded and returned nothing.
39 NoData,
40 /// `W`: the statement succeeded and has something to say about it.
41 Warning,
42 /// `I`: informational.
43 Informational,
44 /// `X`: the statement did not succeed.
45 Exception,
46}
47
48impl Severity {
49 /// True when the statement kept its result. Warnings ride along with
50 /// an answer; exceptions replace it.
51 pub const fn is_success(self) -> bool {
52 !matches!(self, Severity::Exception)
53 }
54
55 /// The one character ISO writes it as, which is what a status read
56 /// as a value carries: a client that has to print or compare one
57 /// should not have to pick its own spelling of these five words.
58 pub const fn letter(self) -> &'static str {
59 match self {
60 Severity::Success => "S",
61 Severity::NoData => "N",
62 Severity::Warning => "W",
63 Severity::Informational => "I",
64 Severity::Exception => "X",
65 }
66 }
67}
68
69/// One row of the standard's condition table.
70#[derive(Debug, Clone, Copy)]
71pub struct Condition {
72 /// The five-character GQLSTATUS value, for example `22012`.
73 pub code: &'static str,
74 pub severity: Severity,
75 /// The class name, for example `data exception`.
76 pub class: &'static str,
77 /// The subclass name, for example `division by zero`. `None` on the
78 /// twelve class rows, whose code ends in `000`.
79 pub subclass: Option<&'static str>,
80}
81
82/// A GQLSTATUS value. Constructible only from the generated table, so
83/// every value of this type is a code the standard defines.
84#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
85pub struct GqlStatus(u16);
86
87impl GqlStatus {
88 /// Looks a code up by its five characters. Returns `None` for
89 /// anything the standard does not define, which is how a code
90 /// arriving from outside zu gets checked rather than trusted.
91 pub fn from_code(code: &str) -> Option<Self> {
92 CONDITIONS
93 .iter()
94 .position(|c| c.code == code)
95 .map(|i| GqlStatus(i as u16))
96 }
97
98 /// The row this status names.
99 pub fn condition(self) -> &'static Condition {
100 &CONDITIONS[self.0 as usize]
101 }
102
103 pub fn code(self) -> &'static str {
104 self.condition().code
105 }
106
107 pub fn severity(self) -> Severity {
108 self.condition().severity
109 }
110
111 /// The two characters that open the code, which is the condition
112 /// class: `22` for the data exceptions, `42` for the syntax
113 /// errors, `40` for the rollbacks. A binding raises one exception
114 /// type per class, so this is the field it switches on, and taking
115 /// the first two characters of a five-character code is the sort of
116 /// thing every binding would otherwise write for itself.
117 pub fn class(self) -> &'static str {
118 &self.condition().code[..2]
119 }
120
121 /// The standard's own words for this condition: the class name, and
122 /// the subclass name after it when there is one. This is the text a
123 /// conformance harness compares against, so zu never paraphrases it.
124 /// Anything zu wants to add goes in [`DiagnosticRecord::detail`].
125 pub fn standard_text(self) -> String {
126 let c = self.condition();
127 match c.subclass {
128 Some(sub) => format!("{}, {sub}", c.class),
129 None => c.class.to_string(),
130 }
131 }
132
133 /// The page that documents this condition. Derived from the code
134 /// rather than stored, because a table of eighty urls is eighty
135 /// chances for one of them to be the url of a different condition.
136 pub fn doc_url(self) -> String {
137 format!("{DOC_BASE}{}", self.code())
138 }
139
140 /// Whether running the same statement again could succeed.
141 ///
142 /// True for `40000 transaction rollback`, which is the engine
143 /// saying it undid the work and nothing of it is in the file. False
144 /// for `40003 statement completion unknown`, which is the same
145 /// class and the opposite advice: a statement that may or may not
146 /// have committed is one a retry could apply twice, and a caller
147 /// that wants to retry it has to establish which happened first.
148 /// False for everything else, since a statement that failed to
149 /// parse parses no better the second time.
150 pub fn retryable(self) -> bool {
151 self.code() == "40000"
152 }
153}
154
155/// Where a condition is written up. The code goes on the end, so an
156/// error hands the reader a url rather than a code to go and search
157/// for, which is the difference between a message a user can act on
158/// and a message a user has to research.
159pub const DOC_BASE: &str = "https://zu.dev/docs/errors/";
160
161impl fmt::Debug for GqlStatus {
162 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
163 write!(f, "GqlStatus({})", self.code())
164 }
165}
166
167impl fmt::Display for GqlStatus {
168 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
169 f.write_str(self.code())
170 }
171}
172
173/// Where in the statement text a condition was raised, said three ways.
174///
175/// `line` and `column` are 1-based and the column counts characters
176/// rather than bytes, so a line of multi-byte text does not read as
177/// wider than it looks. That pair is what an editor or a shell wants:
178/// it has printed the line already and needs somewhere to put the
179/// caret.
180///
181/// `offset` is the same place as a byte index into the statement, and
182/// it is here for the caller the pair does not serve: a tool that holds
183/// the text and wants to slice it, an editor mapping into a buffer it
184/// indexes by byte, a highlighter marking a range. Recovering it from
185/// the pair means counting lines and characters again, over text the
186/// engine had in hand when it raised the condition. It is always on a
187/// character boundary of that text, so slicing at it cannot panic.
188#[derive(Debug, Clone, Copy, PartialEq, Eq)]
189pub struct Position {
190 /// Bytes into the statement, 0-based.
191 pub offset: u32,
192 pub line: u32,
193 pub column: u32,
194}
195
196impl Position {
197 /// The place `offset` bytes into `source`. An offset past the end
198 /// lands at the end, which is where an error about a query that
199 /// stopped too early belongs, and an offset inside a character
200 /// lands on the start of that character.
201 pub fn of(source: &str, offset: usize) -> Self {
202 let offset = boundary(source, offset);
203 let mut line = 1u32;
204 let mut column = 1u32;
205 for (ix, ch) in source.char_indices() {
206 if ix >= offset {
207 break;
208 }
209 if ch == '\n' {
210 line += 1;
211 column = 1;
212 } else {
213 column += 1;
214 }
215 }
216 Position {
217 offset: u32::try_from(offset).unwrap_or(u32::MAX),
218 line,
219 column,
220 }
221 }
222}
223
224/// The nearest character boundary of `source` at or before `offset`,
225/// with an offset past the end landing on the end.
226fn boundary(source: &str, offset: usize) -> usize {
227 let mut offset = offset.min(source.len());
228 while !source.is_char_boundary(offset) {
229 offset -= 1;
230 }
231 offset
232}
233
234/// The longest line quoted back as an excerpt. A line longer than this
235/// was written by a program rather than by a person, and nobody is
236/// going to read four kilobytes of it under a caret. It is left out
237/// rather than cut short, because a cut line puts the column somewhere
238/// other than where the column says it is.
239const EXCERPT_LIMIT: usize = 4096;
240
241/// The line `offset` falls on, without its newline, or `None` when
242/// that line is empty or too long to quote.
243fn line_at(source: &str, offset: usize) -> Option<&str> {
244 let offset = boundary(source, offset);
245 let start = source[..offset].rfind('\n').map_or(0, |ix| ix + 1);
246 let end = source[offset..]
247 .find('\n')
248 .map_or(source.len(), |ix| offset + ix);
249 let line = source[start..end].trim_end_matches('\r');
250 (!line.is_empty() && line.len() <= EXCERPT_LIMIT).then_some(line)
251}
252
253impl fmt::Display for Position {
254 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
255 write!(f, "line {}, column {}", self.line, self.column)
256 }
257}
258
259/// What a condition is about, when it is about something a statement
260/// named.
261///
262/// ISO 23.2 calls this the subject of the diagnostic record, and what it
263/// buys is the difference between a message and a fact. `42002` says a
264/// name is not defined and the detail says which one in English; the
265/// subject says which one in a field, so a client underlining the name,
266/// a linter counting the labels a graph is missing, or a driver mapping
267/// the condition onto its own exception type never has to read the
268/// sentence back.
269///
270/// The variants are the kinds of thing a GQL statement can name, and
271/// there is deliberately no `Other(String)`: a condition about something
272/// with no kind here has no subject, which is honest, where a catch-all
273/// would be a second message field wearing the subject's name.
274#[derive(Debug, Clone, PartialEq, Eq)]
275pub enum Subject {
276 /// A graph, by the name the statement reached it under.
277 Graph(String),
278 /// A schema, by its path.
279 Schema(String),
280 /// A label, which is what names a node type or an edge type.
281 Label(String),
282 /// A property, by the name written after the dot or before the
283 /// colon.
284 Property(String),
285 /// A binding variable.
286 Variable(String),
287 /// A value type, spelled the way a statement would spell it.
288 Type(String),
289 /// A function or a procedure, by name.
290 Function(String),
291}
292
293impl Subject {
294 /// What kind of thing this is, in one word, for a caller rendering
295 /// the record rather than matching on it.
296 pub const fn kind(&self) -> &'static str {
297 match self {
298 Subject::Graph(_) => "graph",
299 Subject::Schema(_) => "schema",
300 Subject::Label(_) => "label",
301 Subject::Property(_) => "property",
302 Subject::Variable(_) => "variable",
303 Subject::Type(_) => "type",
304 Subject::Function(_) => "function",
305 }
306 }
307
308 /// The name itself, without the kind.
309 pub fn name(&self) -> &str {
310 match self {
311 Subject::Graph(s)
312 | Subject::Schema(s)
313 | Subject::Label(s)
314 | Subject::Property(s)
315 | Subject::Variable(s)
316 | Subject::Type(s)
317 | Subject::Function(s) => s,
318 }
319 }
320}
321
322impl fmt::Display for Subject {
323 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
324 write!(f, "{} {}", self.kind(), self.name())
325 }
326}
327
328/// What zu hands back when a condition is raised: the standard's code and
329/// zu's own account of what happened.
330///
331/// The two are kept apart on purpose. `status` is comparable across
332/// engines and is what a conformance run grades. `detail` is ours and can
333/// say whatever is most useful, including the line and column, without
334/// putting that in the field a harness matches on.
335///
336/// `position` is that line and column again, as a pair. The detail keeps
337/// saying it because a message a user reads should be complete on its
338/// own, and the pair exists because a caller that wants to underline the
339/// offending token should not have to parse English back into numbers.
340///
341/// `excerpt` is the line that position falls on, kept because the
342/// caller furthest from the statement is the one most likely to be
343/// showing this to a person: a driver, a notebook cell, a log line. The
344/// engine has the text in hand when it raises the condition and the
345/// caller may not have it at all by the time it prints one.
346#[derive(Debug, Clone, PartialEq, Eq)]
347pub struct DiagnosticRecord {
348 pub status: GqlStatus,
349 pub detail: String,
350 /// Where in the statement, for the conditions that happen somewhere.
351 /// A division by zero happens at runtime and has no token to point
352 /// at, so this is `None` rather than a guess at one.
353 pub position: Option<Position>,
354 /// The whole line `position` is on, without its newline, so that
355 /// `column` indexes into it. `None` when there is no position, when
356 /// the line is empty, and when it is longer than a person is going
357 /// to read, which are the three cases where quoting it back helps
358 /// nobody.
359 pub excerpt: Option<String>,
360 /// What the condition is about, where it is about something the
361 /// statement named. `None` for the conditions that are about no
362 /// particular thing: a division by zero is about an expression and
363 /// an expression has no name.
364 pub subject: Option<Subject>,
365 /// The graph the statement was running against, and the schema that
366 /// graph was reached through. Both are filled at the session
367 /// boundary rather than at the raise site, because that is the one
368 /// place that knows them and there are two hundred raise sites.
369 pub graph: Option<String>,
370 pub schema: Option<String>,
371}
372
373impl DiagnosticRecord {
374 pub fn new(status: GqlStatus, detail: impl Into<String>) -> Self {
375 DiagnosticRecord {
376 status,
377 detail: detail.into(),
378 position: None,
379 excerpt: None,
380 subject: None,
381 graph: None,
382 schema: None,
383 }
384 }
385
386 /// The same, about a thing the statement named.
387 ///
388 /// Written as a builder so a raise site reads as one expression and
389 /// so that adding the subject to a site never reshapes the call it
390 /// was already making.
391 pub fn about(mut self, subject: Subject) -> Self {
392 self.subject = Some(subject);
393 self
394 }
395
396 /// Where the statement was running, filled in on the way out.
397 ///
398 /// It does not overwrite: a condition raised about a graph other
399 /// than the working one has already said which, and the session
400 /// saying otherwise on the way past would be the session being
401 /// wrong.
402 pub fn within(&mut self, graph: &str, schema: &str) {
403 self.graph.get_or_insert_with(|| graph.to_string());
404 self.schema.get_or_insert_with(|| schema.to_string());
405 }
406
407 /// The same, raised at a place. The position is written into the
408 /// detail as well, ahead of it and separated by a colon, which is
409 /// the form every parser message already had.
410 pub fn at(status: GqlStatus, position: Position, detail: impl fmt::Display) -> Self {
411 DiagnosticRecord {
412 position: Some(position),
413 ..DiagnosticRecord::new(status, format!("{position}: {detail}"))
414 }
415 }
416
417 /// The same again, raised at a byte offset into the statement text.
418 ///
419 /// This is the form to reach for wherever the text is in hand,
420 /// which is every place inside the front end, because it is the
421 /// only form that can fill the excerpt: the line comes from the
422 /// source and nothing downstream of here still has it.
423 pub fn in_source(
424 status: GqlStatus,
425 source: &str,
426 offset: usize,
427 detail: impl fmt::Display,
428 ) -> Self {
429 let position = Position::of(source, offset);
430 DiagnosticRecord {
431 excerpt: line_at(source, offset).map(str::to_string),
432 ..DiagnosticRecord::at(status, position, detail)
433 }
434 }
435
436 pub fn severity(&self) -> Severity {
437 self.status.severity()
438 }
439
440 /// The page that documents the condition this record carries.
441 pub fn doc_url(&self) -> String {
442 self.status.doc_url()
443 }
444
445 /// Whether running the statement again could succeed.
446 pub fn retryable(&self) -> bool {
447 self.status.retryable()
448 }
449}
450
451impl fmt::Display for DiagnosticRecord {
452 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
453 if self.detail.is_empty() {
454 write!(f, "{}: {}", self.status.code(), self.status.standard_text())
455 } else {
456 write!(f, "{}: {}", self.status.code(), self.detail)
457 }
458 }
459}
460
461/// Every condition the standard defines, in code order.
462pub fn all() -> &'static [Condition] {
463 CONDITIONS
464}
465
466/// The 68 subclass rows, which are the conformance denominator.
467pub fn subclass_rows() -> impl Iterator<Item = &'static Condition> {
468 CONDITIONS.iter().filter(|c| c.subclass.is_some())
469}
470
471#[cfg(test)]
472mod tests {
473 use super::*;
474
475 #[test]
476 fn the_table_is_the_standard_table() {
477 assert_eq!(CONDITIONS.len(), 80, "12 class rows plus 68 subclass rows");
478 assert_eq!(
479 subclass_rows().count(),
480 68,
481 "68 subclass rows, the conformance denominator"
482 );
483 }
484
485 #[test]
486 fn a_statement_that_did_nothing_notable_has_a_code_for_that() {
487 // The artifact spells `00` as a container with `001` inside it,
488 // so a generator that only emits class rows for the self-closing
489 // classes has no way to say "this worked". Everything the shell
490 // reports on a successful statement hangs off this.
491 assert_eq!(codes::C00000.code(), "00000");
492 assert_eq!(codes::C00000.standard_text(), "successful completion");
493 assert_eq!(codes::C00000.severity(), Severity::Success);
494 assert_eq!(
495 codes::C00001.standard_text(),
496 "successful completion, omitted result"
497 );
498 }
499
500 #[test]
501 fn codes_are_unique_and_sorted() {
502 let mut seen: Vec<&str> = CONDITIONS.iter().map(|c| c.code).collect();
503 let n = seen.len();
504 seen.sort_unstable();
505 seen.dedup();
506 assert_eq!(seen.len(), n, "duplicate GQLSTATUS code in the table");
507 let codes: Vec<&str> = CONDITIONS.iter().map(|c| c.code).collect();
508 assert_eq!(codes, seen, "table is not in code order");
509 }
510
511 #[test]
512 fn lookup_round_trips_and_rejects_inventions() {
513 for c in CONDITIONS {
514 let status = GqlStatus::from_code(c.code).expect("code in table");
515 assert_eq!(status.code(), c.code);
516 }
517 assert!(GqlStatus::from_code("99999").is_none());
518 assert!(GqlStatus::from_code("ZU001").is_none());
519 assert!(GqlStatus::from_code("").is_none());
520 }
521
522 #[test]
523 fn severity_follows_the_class_letter() {
524 assert_eq!(codes::C00001.severity(), Severity::Success);
525 assert_eq!(codes::C01G11.severity(), Severity::Warning);
526 assert_eq!(codes::C02000.severity(), Severity::NoData);
527 assert_eq!(codes::C22012.severity(), Severity::Exception);
528 assert!(codes::C01G11.severity().is_success());
529 assert!(!codes::C42001.severity().is_success());
530 }
531
532 #[test]
533 fn standard_text_is_the_standards_words() {
534 assert_eq!(
535 codes::C22012.standard_text(),
536 "data exception, division by zero"
537 );
538 assert_eq!(
539 codes::C42001.standard_text(),
540 "syntax error or access rule violation, invalid syntax"
541 );
542 // A class-only row has no comma to append.
543 assert_eq!(codes::CG2000.standard_text(), "graph type violation");
544 }
545
546 #[test]
547 fn a_record_prefers_our_detail_but_never_loses_the_code() {
548 let bare = DiagnosticRecord::new(codes::C22012, "");
549 assert_eq!(bare.to_string(), "22012: data exception, division by zero");
550 let ours = DiagnosticRecord::new(codes::C42001, "line 1, column 7: expected MATCH");
551 assert_eq!(ours.to_string(), "42001: line 1, column 7: expected MATCH");
552 assert_eq!(ours.status.code(), "42001");
553 }
554
555 #[test]
556 fn a_position_reads_the_same_way_it_did_when_it_was_only_prose() {
557 // The pair is added to the record, not swapped for the words:
558 // a message that stopped saying where would be a message a
559 // user has to go and look something up to act on.
560 let at = Position {
561 offset: 6,
562 line: 1,
563 column: 7,
564 };
565 let raised = DiagnosticRecord::at(codes::C42001, at, "expected MATCH");
566 assert_eq!(
567 raised.to_string(),
568 "42001: line 1, column 7: expected MATCH"
569 );
570 assert_eq!(raised.position, Some(at));
571 assert_eq!(at.to_string(), "line 1, column 7");
572 // And a record made the old way has no position rather than
573 // one parsed back out of its own detail.
574 assert!(DiagnosticRecord::new(codes::C22012, "").position.is_none());
575 }
576
577 #[test]
578 fn an_offset_lands_on_the_line_and_column_a_reader_would_count() {
579 let source = "MATCH (n)\nWHERE n.x\nRETURN n";
580 let at = |offset, line, column| Position {
581 offset,
582 line,
583 column,
584 };
585 assert_eq!(Position::of(source, 0), at(0, 1, 1));
586 assert_eq!(Position::of(source, 6), at(6, 1, 7));
587 // The newline itself belongs to the line it ends, and the byte
588 // after it starts the next one at column 1.
589 assert_eq!(Position::of(source, 9), at(9, 1, 10));
590 assert_eq!(Position::of(source, 10), at(10, 2, 1));
591 assert_eq!(Position::of(source, 20), at(20, 3, 1));
592 // Past the end is the end, which is where an error about a
593 // query that stopped too early belongs, and the offset says the
594 // end too rather than the number nobody could index with.
595 assert_eq!(Position::of(source, 9999), at(28, 3, 9));
596 }
597
598 #[test]
599 fn a_column_counts_characters_and_not_the_bytes_they_took() {
600 // Four characters in, on a line where those four took ten
601 // bytes. A column of 11 would point past the end of a line the
602 // user sees as four wide.
603 let source = "RETURN 'héllo wörld'";
604 let offset = source.find('w').expect("w");
605 assert_eq!(
606 Position::of(source, offset),
607 Position {
608 offset: 15,
609 line: 1,
610 column: 15
611 }
612 );
613 // The offset is a byte index into that same text, so slicing at
614 // it is the point of having it, and an offset landing inside a
615 // character walks back to the start of it rather than cutting
616 // one in half.
617 let at = Position::of(source, offset);
618 assert_eq!(&source[at.offset as usize..], "wörld'");
619 let inside = source.find('é').expect("e") + 1;
620 assert_eq!(Position::of(source, inside).offset as usize, inside - 1);
621 }
622
623 #[test]
624 fn an_excerpt_is_the_line_the_column_counts_into() {
625 let source = "MATCH (n)\nWHERE n.x = 1\nRETURN n";
626 let offset = source.find("n.x").expect("n.x");
627 let record = DiagnosticRecord::in_source(codes::C42001, source, offset, "no such property");
628 let excerpt = record.excerpt.as_deref().expect("a line to quote");
629 assert_eq!(excerpt, "WHERE n.x = 1");
630 // Which is what makes the column usable: it counts characters
631 // into the excerpt, so a caret goes under the token.
632 let position = record.position.expect("a place");
633 assert_eq!(position.line, 2);
634 let caret: String = excerpt
635 .chars()
636 .take(position.column as usize - 1)
637 .map(|_| ' ')
638 .chain(['^'])
639 .collect();
640 assert_eq!(caret, " ^");
641 assert_eq!(&source[position.offset as usize..][..3], "n.x");
642 // The words are unchanged by any of it, so a caller that only
643 // prints the message still reads the same sentence.
644 assert_eq!(
645 record.to_string(),
646 "42001: line 2, column 7: no such property"
647 );
648 }
649
650 #[test]
651 fn a_line_nobody_would_read_is_left_out_rather_than_cut() {
652 // An empty line quotes as nothing, so it says nothing.
653 let record = DiagnosticRecord::in_source(codes::C42001, "\n\nRETURN 1", 1, "empty");
654 assert!(record.excerpt.is_none());
655 // And a generated line past the limit is dropped whole, since
656 // a cut one would put the column somewhere it is not.
657 let long = format!("RETURN {}", "1 + ".repeat(2000));
658 let record = DiagnosticRecord::in_source(codes::C42001, &long, 7, "long");
659 assert!(long.len() > 4096, "the fixture has to pass the limit");
660 assert!(record.excerpt.is_none());
661 // A record made without the text has no excerpt either, rather
662 // than an empty one that reads as a blank line.
663 assert!(DiagnosticRecord::new(codes::C22012, "").excerpt.is_none());
664 }
665
666 #[test]
667 fn a_condition_says_where_it_is_written_up_and_whether_to_try_again() {
668 assert_eq!(codes::C42001.class(), "42");
669 assert_eq!(
670 codes::C42001.doc_url(),
671 "https://zu.dev/docs/errors/42001",
672 "the code is the page, so a message hands over a link rather than a thing to search for"
673 );
674 // A rollback undid the work, so the same statement can run
675 // again. Statement completion unknown is the same class and the
676 // opposite advice, because a retry could apply it twice.
677 assert!(codes::C40000.retryable());
678 assert!(!codes::C40003.retryable());
679 assert!(!codes::C42001.retryable());
680 assert!(!codes::C22012.retryable());
681 }
682}