Skip to main content

laminapdf_syntax/generated/
codes.rs

1// @generated by cargo xtask gen codes. DO NOT EDIT.
2//! Every error and warning code the Rust crates and the WASM bindings raise, from
3//! `fixtures/codes.json` (ADR 0026 §3): kind, summary, hint and `docsUrl` per code.
4//! `cargo xtask check docs` fails when this file is stale.
5#![allow(
6    clippy::too_many_lines,
7    clippy::match_same_arms,
8    clippy::doc_markdown,
9    reason = "generated: one match arm per code; summaries are codes.json text"
10)]
11
12use crate::ErrorKind;
13
14/// The base of every `docsUrl` (ADR 0026 §6): `DOCS_URL_BASE` + code + `DOCS_URL_SUFFIX`.
15///
16/// Added in 0.2.0.
17pub const DOCS_URL_BASE: &str = "https://docs.laminapdf.com/reference/codes/";
18
19/// The suffix of every `docsUrl` (ADR 0026 §6).
20///
21/// Added in 0.2.0.
22pub const DOCS_URL_SUFFIX: &str = "/";
23
24/// Whether two byte strings are equal, in a `const fn`.
25const fn bytes_eq(a: &[u8], b: &[u8]) -> bool {
26    if a.len() != b.len() {
27        return false;
28    }
29    let (mut a, mut b) = (a, b);
30    while let ([x, a_rest @ ..], [y, b_rest @ ..]) = (a, b) {
31        if *x != *y {
32            return false;
33        }
34        a = a_rest;
35        b = b_rest;
36    }
37    true
38}
39
40/// Every error code lamina's Rust crates and its WASM binding raise (the codes only
41/// `@laminapdf/sdk` raises are not here), in `codes.json` order.
42///
43/// Added in 0.2.0.
44#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
45#[non_exhaustive]
46pub enum ErrorCode {
47    /// `not-pdf`: the input does not look like a PDF at all.
48    NotPdf,
49    /// `missing-root`: no document catalog (/Root) was found, even after repair.
50    MissingRoot,
51    /// `reference-cycle`: a reference chain or the page tree loops back on itself.
52    ReferenceCycle,
53    /// `limit-exceeded`: a hard Limits value was exceeded.
54    LimitExceeded,
55    /// `strict`: strict mode refused something the tolerant reader would have repaired.
56    Strict,
57    /// `data-pending`: the ByteSource has not fetched the byte ranges the call needs yet.
58    DataPending,
59    /// `source`: the ByteSource failed to read.
60    Source,
61    /// `type`: an object had a different type than the structure requires.
62    Type,
63    /// `invalid-structure`: an object stream, xref section or filter parameter was malformed.
64    InvalidStructure,
65    /// `unset-object`: a writer object number was reserved but never given a value.
66    UnsetObject,
67    /// `repaired-base`: an incremental update was requested for a document whose xref needed repair.
68    RepairedBase,
69    /// `encrypted-base`: a save of an encrypted document was requested.
70    EncryptedBase,
71    /// `password-required`: the document is encrypted with a user password and none was given.
72    PasswordRequired,
73    /// `wrong-password`: the given password is neither the user nor the owner password.
74    WrongPassword,
75    /// `unsupported-security-handler`: the document uses a security handler Lamina PDF cannot decrypt.
76    UnsupportedSecurityHandler,
77    /// `unexpected-eof`: the input ended before a complete token or object was read.
78    UnexpectedEof,
79    /// `syntax`: a token or structure did not match the PDF grammar.
80    Syntax,
81    /// `unsupported-filter`: a stream uses a filter Lamina PDF does not implement.
82    UnsupportedFilter,
83    /// `decompress`: compressed stream data was corrupt.
84    Decompress,
85    /// `nested-transaction`: a transaction was started, or undo or redo called, while one is open.
86    NestedTransaction,
87    /// `no-transaction`: apply, commit or rollback was called without an open transaction.
88    NoTransaction,
89    /// `unknown-page`: an op names a page the document does not have.
90    UnknownPage,
91    /// `direct-page`: the page is a direct dictionary, which ops cannot edit yet.
92    DirectPage,
93    /// `unsupported-version`: an op log has a schema version this reader does not know.
94    UnsupportedVersion,
95    /// `invalid-op-log`: an op log does not parse: an unknown op or field, a bad value, or not JSON.
96    InvalidOpLog,
97    /// `saved-not-rebased`: the document was saved to a sink Lamina PDF cannot read back and waits for rebase.
98    SavedNotRebased,
99    /// `no-pending-save`: rebase was called without a save waiting for it.
100    NoPendingSave,
101    /// `malformed-xmp`: a metadata edit would replace the document's XMP packet, which can't be read, losing what it holds.
102    MalformedXmp,
103    /// `unknown-source`: an op or a call names a source document that was not added to the session.
104    UnknownSource,
105    /// `open-action-not-destination`: an op would replace or remove the document's open action, which is an action other than a destination.
106    OpenActionNotDestination,
107    /// `unknown-outline-item`: an outline op names a bookmark the outline does not have.
108    UnknownOutlineItem,
109    /// `direct-outline-item`: the bookmark is stored inside another item rather than as an object of its own, so outline ops can't name it yet.
110    DirectOutlineItem,
111    /// `outline-not-a-sibling`: the position names a bookmark that is not a child of the parent the op names.
112    OutlineNotASibling,
113    /// `outline-move-into-itself`: a move would put a bookmark inside itself or one of its descendants.
114    OutlineMoveIntoItself,
115    /// `unknown-named-destination`: the op names a destination the file does not define.
116    UnknownNamedDestination,
117    /// `named-destination-exists`: a rename to a name another destination already has.
118    NamedDestinationExists,
119    /// `empty-destination-name`: a destination name is empty.
120    EmptyDestinationName,
121    /// `link-uri-refused`: a web address that isn't an absolute http, https or mailto address in plain ASCII.
122    LinkUriRefused,
123    /// `view-not-finite`: a destination's coordinates and zoom must be finite numbers.
124    ViewNotFinite,
125    /// `xmp-claim-read-only`: an XMP edit would change the file's PDF/A or PDF/UA identification, which only conversion or a check may set.
126    XmpClaimReadOnly,
127    /// `invalid-xmp-packet`: the XMP packet given to replace the document's doesn't parse.
128    InvalidXmpPacket,
129    /// `invalid-xmp-property`: an XMP property edit names a property, or gives a value, that can't be written.
130    InvalidXmpProperty,
131    /// `no-pages-left`: a page deletion would leave the document with no pages.
132    NoPagesLeft,
133    /// `invalid-op`: an op's values are out of range, such as a page count or a page size.
134    InvalidOp,
135    /// `unknown-annotation`: the op names an annotation that no page of the document lists.
136    UnknownAnnotation,
137    /// `annotation-locked`: the annotation's flags forbid the change: Locked forbids deleting it or changing its properties, LockedContents changing its contents.
138    AnnotationLocked,
139    /// `annotation-not-editable`: the annotation can't be edited by the annotation ops: it is a form field's widget, or a direct dictionary with no object of its own.
140    AnnotationNotEditable,
141    /// `not-a-link`: a link op names an annotation that isn't a link.
142    NotALink,
143    /// `link-not-tagged`: the file claims PDF/UA-1 but has no structure tree for a new link to join.
144    LinkNotTagged,
145    /// `appearance-unavailable`: the document has no appearance generator, so it can't draw a new annotation.
146    AppearanceUnavailable,
147    /// `invalid-label-ranges`: page label ranges whose first isn't on the first page, that are out of page order or share a page, or that number from 0.
148    InvalidLabelRanges,
149    /// `sink`: the sink failed to take the bytes or could not give them back.
150    Sink,
151    /// `not-rebased`: the output was written, but rebasing the document onto it failed.
152    NotRebased,
153    /// `sink-not-empty`: the sink already held bytes before the save started.
154    SinkNotEmpty,
155    /// `would-invalidate-signatures`: the save would break one or more signatures.
156    WouldInvalidateSignatures,
157    /// `requires-rewrite`: an incremental save was requested but only a full rewrite is safe.
158    RequiresRewrite,
159    /// `invalid-font`: font bytes could not be read as a font.
160    InvalidFont,
161    /// `collection-index`: a font collection member past the end of the collection was asked for.
162    CollectionIndex,
163    /// `unknown-axis`: an instance was asked for on a variation axis the font does not have.
164    UnknownAxis,
165    /// `font-not-embeddable`: the font's OS/2 fsType forbids embedding.
166    FontNotEmbeddable,
167    /// `missing-glyph`: the font has no glyph for a character of the text.
168    MissingGlyph,
169    /// `glyph-out-of-range`: a glyph ID at or past the font's glyph count was used.
170    GlyphOutOfRange,
171    /// `unknown-font`: a FontKey was used with a registry that did not hand it out.
172    UnknownFont,
173    /// `subset-failed`: subsetting a font failed.
174    SubsetFailed,
175    /// `invalid-axis-value`: a variation axis value was NaN or infinite.
176    InvalidAxisValue,
177    /// `wrong-document`: finish_fonts was given a document the registry did not reserve its fonts in.
178    WrongDocument,
179    /// `invalid-feature`: an OpenType feature setting did not parse.
180    InvalidFeature,
181    /// `invalid-text-range`: a byte range was out of bounds or not on character boundaries of the text.
182    InvalidTextRange,
183    /// `invalid-spans`: the styled spans given for a paragraph do not cover its text once, in order.
184    InvalidSpans,
185    /// `unsupported-layout-option`: a layout option that is not implemented yet was asked for.
186    UnsupportedLayoutOption,
187    /// `font-mismatch`: a shaped run was given with a font key for a different font than it was shaped with.
188    FontMismatch,
189    /// `encoding-full`: a standard 14 font has no free one-byte code left for another glyph.
190    EncodingFull,
191    /// `font-not-shapable`: a standard 14 font was given to shaping or layout, which need a font program.
192    FontNotShapable,
193    /// `invalid-image`: image bytes are not a readable image of the format they were given as.
194    InvalidImage,
195    /// `unsupported-image`: the image uses a feature that PDF or Lamina PDF does not support.
196    UnsupportedImage,
197    /// `image-too-large`: the image needs more memory than the builder allows (a decoded PNG over 256 MiB, or raw dimensions whose size overflows).
198    ImageTooLarge,
199    /// `image-data-length`: raw image samples are not width x height x channels bytes long.
200    ImageDataLength,
201    /// `invalid-icc-profile`: the bytes are not a usable ICC profile.
202    InvalidIccProfile,
203    /// `color-components`: a colour has the wrong number of components for its colour space.
204    ColorComponents,
205    /// `invalid-color`: a colour string is not of the form #rgb or #rrggbb.
206    InvalidColor,
207    /// `invalid-geometry`: a page size, box, /UserUnit, drawing value (coordinate, matrix, line width, dash, miter limit) or image size is not usable.
208    InvalidGeometry,
209    /// `text-overflow`: a text box's lines don't all fit its height and its options asked for an error.
210    TextOverflow,
211    /// `page-index-out-of-range`: a link, outline item or destination names a page index the document doesn't have.
212    PageIndexOutOfRange,
213    /// `unknown-destination`: a link or outline item names a destination that was never defined.
214    UnknownDestination,
215    /// `invalid-page-labels`: page label ranges that don't start at page 0, don't increase, start past the last page or number from 0.
216    InvalidPageLabels,
217    /// `tag-element-not-open`: a structure element resumed or closed isn't open.
218    TagElementNotOpen,
219    /// `tag-element-unclosed`: structure elements opened across pages were never closed.
220    TagElementUnclosed,
221    /// `profile-version-conflict`: the PDF version asked for is one the profile doesn't allow (PDF/UA-1, PDF/A-2 and PDF/A-3 are based on PDF 1.7).
222    ProfileVersionConflict,
223    /// `missing-title`: PDF/UA-1 needs a document title, and the metadata gives none.
224    MissingTitle,
225    /// `missing-lang`: PDF/UA-1 needs the document's natural language, and none was set.
226    MissingLang,
227    /// `missing-alt-text`: a Figure or Formula has no alternate text (/Alt or /ActualText), which PDF/UA-1 requires.
228    MissingAltText,
229    /// `untagged-content`: content was drawn outside every structure element and artifact, which PDF/UA-1 forbids.
230    UntaggedContent,
231    /// `heading-level-skipped`: a heading skips a level (the first is not H1, or an H3 follows an H1), which PDF/UA-1 forbids.
232    HeadingLevelSkipped,
233    /// `unnumbered-heading-misused`: an unnumbered H heading shares its parent with another H, or the document also uses H1-H6, which PDF/UA-1 forbids.
234    UnnumberedHeadingMisused,
235    /// `invalid-structure-nesting`: a table or list element sits in a parent its type doesn't allow (a TD outside a TR, a P directly in a Table).
236    InvalidStructureNesting,
237    /// `link-without-structure`: a link annotation has no Link structure element (it was drawn inside an artifact), which PDF/UA-1 forbids.
238    LinkWithoutStructure,
239    /// `link-without-contents`: a link annotation has no description (/Contents), which PDF/UA-1 requires.
240    LinkWithoutContents,
241    /// `font-not-embedded`: a standard 14 font, which is never embedded, was used under a profile that needs every font embedded.
242    FontNotEmbedded,
243    /// `glyph-without-unicode`: a glyph was drawn without a Unicode value, which PDF/A-2u and PDF/UA-1 forbid.
244    GlyphWithoutUnicode,
245    /// `device-color-without-output-intent`: a DeviceCMYK colour or image was used, but the PDF/A output intent is sRGB.
246    DeviceColorWithoutOutputIntent,
247    /// `embedded-file-forbidden`: PDF/A-2 doesn't allow attached files that aren't PDF/A themselves.
248    EmbeddedFileForbidden,
249    /// `embedded-file-without-mime-type`: an attached file has no MIME type, which every PDF/A profile requires.
250    EmbeddedFileWithoutMimeType,
251    /// `flow-content-too-large`: a line or a figure of a flow is taller than the page's body, so no page can hold it.
252    FlowContentTooLarge,
253    /// `flow-layout-unstable`: a flow's contents page kept changing its page numbers after four layouts.
254    FlowLayoutUnstable,
255    /// `invalid-document`: a laminapdf.document/1 document has an unknown key, a missing one or a value of the wrong kind.
256    InvalidDocument,
257    /// `template-data-missing`: a template's $data, $each or $item points to a value the data doesn't have.
258    TemplateDataMissing,
259    /// `template-data-type`: a template's placeholder found data of the wrong kind: $each over something that isn't a list, or text from an object.
260    TemplateDataType,
261    /// `template-too-large`: a template would fill in more values, or nest deeper, than a document may hold.
262    TemplateTooLarge,
263    /// `render-too-large`: the requested tile is larger than the render limits allow; nothing was allocated.
264    RenderTooLarge,
265    /// `render-failed`: the render engine could not open the document or draw the page.
266    RenderFailed,
267    /// `render-backend-unavailable`: the render engine is not available: its library or module could not be loaded.
268    RenderBackendUnavailable,
269    /// `export-failed`: an export's PNG, JPEG or TIFF encoder failed on a page that was drawn.
270    ExportFailed,
271    /// `model-failed`: a layout model, OCR engine or page renderer plugged into an extraction failed; the extraction stops with no partial result.
272    ModelFailed,
273    /// `model-result-unexpected`: a model result was handed to an extraction job that hadn't asked for it, or was the other model's result.
274    ModelResultUnexpected,
275    /// `model-needs-host`: an extraction in one call was given a model whose results only the host can give: a host model, or a plug-in model without a page renderer.
276    ModelNeedsHost,
277    /// `cancelled`: a CancelToken stopped the work; the job is finished and returned no partial result.
278    Cancelled,
279    /// `job-finished`: a job was stepped after it had finished, failed or been cancelled.
280    JobFinished,
281    /// `document-changed`: the document a job was created for changed (an edit, undo, redo, save or rebase) or a different document was passed to step.
282    DocumentChanged,
283    /// `revision-index-out-of-range`: an earlier revision was asked for by an index past the file's last revision.
284    RevisionIndexOutOfRange,
285    /// `builder-finished`: a builder or one of its pages was used after it finished.
286    BuilderFinished,
287    /// `disposed`: a document, builder or other handle was used after free(), or after the using block that held it ended.
288    Disposed,
289    /// `invalid-argument`: a value passed to a binding does not have the shape its type declares.
290    InvalidArgument,
291    /// `source-budget-exceeded`: a sparse source was given more bytes than its byte budget allows.
292    SourceBudgetExceeded,
293    /// `unknown-option`: an options record passed to a binding has a key Lamina PDF does not know.
294    UnknownOption,
295    /// `invalid-command-line`: the command line doesn't parse: an unknown command or flag, a missing argument, a bad value, or stdin named twice.
296    InvalidCommandLine,
297    /// `invalid-page-range`: a page range doesn't fit the grammar, or names a page the document lacks.
298    InvalidPageRange,
299    /// `binary-output-to-terminal`: the command would write a PDF to standard output, and standard output is a terminal.
300    BinaryOutputToTerminal,
301    /// `unknown-code`: explain was given a code that isn't a Lamina PDF error or warning code.
302    UnknownCode,
303    /// `overwrite-refused`: the output file exists, or the command would modify its input in place, and --force wasn't given.
304    OverwriteRefused,
305    /// `input-unreadable`: an input file, standard input or the password file couldn't be read.
306    InputUnreadable,
307    /// `output-unwritable`: the output couldn't be written: its folder is missing or read-only, the disk is full, or standard output closed.
308    OutputUnwritable,
309    /// `path-outside-roots`: laminapdf mcp was given a path outside its --root folders, or a link that leads out of them.
310    PathOutsideRoots,
311}
312
313impl ErrorCode {
314    /// Every variant, in `codes.json` order.
315    ///
316    /// Added in 0.2.0.
317    pub const ALL: &'static [Self] = &[
318        Self::NotPdf,
319        Self::MissingRoot,
320        Self::ReferenceCycle,
321        Self::LimitExceeded,
322        Self::Strict,
323        Self::DataPending,
324        Self::Source,
325        Self::Type,
326        Self::InvalidStructure,
327        Self::UnsetObject,
328        Self::RepairedBase,
329        Self::EncryptedBase,
330        Self::PasswordRequired,
331        Self::WrongPassword,
332        Self::UnsupportedSecurityHandler,
333        Self::UnexpectedEof,
334        Self::Syntax,
335        Self::UnsupportedFilter,
336        Self::Decompress,
337        Self::NestedTransaction,
338        Self::NoTransaction,
339        Self::UnknownPage,
340        Self::DirectPage,
341        Self::UnsupportedVersion,
342        Self::InvalidOpLog,
343        Self::SavedNotRebased,
344        Self::NoPendingSave,
345        Self::MalformedXmp,
346        Self::UnknownSource,
347        Self::OpenActionNotDestination,
348        Self::UnknownOutlineItem,
349        Self::DirectOutlineItem,
350        Self::OutlineNotASibling,
351        Self::OutlineMoveIntoItself,
352        Self::UnknownNamedDestination,
353        Self::NamedDestinationExists,
354        Self::EmptyDestinationName,
355        Self::LinkUriRefused,
356        Self::ViewNotFinite,
357        Self::XmpClaimReadOnly,
358        Self::InvalidXmpPacket,
359        Self::InvalidXmpProperty,
360        Self::NoPagesLeft,
361        Self::InvalidOp,
362        Self::UnknownAnnotation,
363        Self::AnnotationLocked,
364        Self::AnnotationNotEditable,
365        Self::NotALink,
366        Self::LinkNotTagged,
367        Self::AppearanceUnavailable,
368        Self::InvalidLabelRanges,
369        Self::Sink,
370        Self::NotRebased,
371        Self::SinkNotEmpty,
372        Self::WouldInvalidateSignatures,
373        Self::RequiresRewrite,
374        Self::InvalidFont,
375        Self::CollectionIndex,
376        Self::UnknownAxis,
377        Self::FontNotEmbeddable,
378        Self::MissingGlyph,
379        Self::GlyphOutOfRange,
380        Self::UnknownFont,
381        Self::SubsetFailed,
382        Self::InvalidAxisValue,
383        Self::WrongDocument,
384        Self::InvalidFeature,
385        Self::InvalidTextRange,
386        Self::InvalidSpans,
387        Self::UnsupportedLayoutOption,
388        Self::FontMismatch,
389        Self::EncodingFull,
390        Self::FontNotShapable,
391        Self::InvalidImage,
392        Self::UnsupportedImage,
393        Self::ImageTooLarge,
394        Self::ImageDataLength,
395        Self::InvalidIccProfile,
396        Self::ColorComponents,
397        Self::InvalidColor,
398        Self::InvalidGeometry,
399        Self::TextOverflow,
400        Self::PageIndexOutOfRange,
401        Self::UnknownDestination,
402        Self::InvalidPageLabels,
403        Self::TagElementNotOpen,
404        Self::TagElementUnclosed,
405        Self::ProfileVersionConflict,
406        Self::MissingTitle,
407        Self::MissingLang,
408        Self::MissingAltText,
409        Self::UntaggedContent,
410        Self::HeadingLevelSkipped,
411        Self::UnnumberedHeadingMisused,
412        Self::InvalidStructureNesting,
413        Self::LinkWithoutStructure,
414        Self::LinkWithoutContents,
415        Self::FontNotEmbedded,
416        Self::GlyphWithoutUnicode,
417        Self::DeviceColorWithoutOutputIntent,
418        Self::EmbeddedFileForbidden,
419        Self::EmbeddedFileWithoutMimeType,
420        Self::FlowContentTooLarge,
421        Self::FlowLayoutUnstable,
422        Self::InvalidDocument,
423        Self::TemplateDataMissing,
424        Self::TemplateDataType,
425        Self::TemplateTooLarge,
426        Self::RenderTooLarge,
427        Self::RenderFailed,
428        Self::RenderBackendUnavailable,
429        Self::ExportFailed,
430        Self::ModelFailed,
431        Self::ModelResultUnexpected,
432        Self::ModelNeedsHost,
433        Self::Cancelled,
434        Self::JobFinished,
435        Self::DocumentChanged,
436        Self::RevisionIndexOutOfRange,
437        Self::BuilderFinished,
438        Self::Disposed,
439        Self::InvalidArgument,
440        Self::SourceBudgetExceeded,
441        Self::UnknownOption,
442        Self::InvalidCommandLine,
443        Self::InvalidPageRange,
444        Self::BinaryOutputToTerminal,
445        Self::UnknownCode,
446        Self::OverwriteRefused,
447        Self::InputUnreadable,
448        Self::OutputUnwritable,
449        Self::PathOutsideRoots,
450    ];
451
452    /// The code with this name, if there is one.
453    ///
454    /// Added in 0.2.0.
455    #[must_use]
456    pub const fn from_code(code: &str) -> Option<Self> {
457        let mut rest = Self::ALL;
458        while let [first, tail @ ..] = rest {
459            if bytes_eq(first.as_str().as_bytes(), code.as_bytes()) {
460                return Some(*first);
461            }
462            rest = tail;
463        }
464        None
465    }
466
467    /// The kebab-case code.
468    ///
469    /// Added in 0.2.0.
470    #[must_use]
471    pub const fn as_str(self) -> &'static str {
472        match self {
473            Self::NotPdf => "not-pdf",
474            Self::MissingRoot => "missing-root",
475            Self::ReferenceCycle => "reference-cycle",
476            Self::LimitExceeded => "limit-exceeded",
477            Self::Strict => "strict",
478            Self::DataPending => "data-pending",
479            Self::Source => "source",
480            Self::Type => "type",
481            Self::InvalidStructure => "invalid-structure",
482            Self::UnsetObject => "unset-object",
483            Self::RepairedBase => "repaired-base",
484            Self::EncryptedBase => "encrypted-base",
485            Self::PasswordRequired => "password-required",
486            Self::WrongPassword => "wrong-password",
487            Self::UnsupportedSecurityHandler => "unsupported-security-handler",
488            Self::UnexpectedEof => "unexpected-eof",
489            Self::Syntax => "syntax",
490            Self::UnsupportedFilter => "unsupported-filter",
491            Self::Decompress => "decompress",
492            Self::NestedTransaction => "nested-transaction",
493            Self::NoTransaction => "no-transaction",
494            Self::UnknownPage => "unknown-page",
495            Self::DirectPage => "direct-page",
496            Self::UnsupportedVersion => "unsupported-version",
497            Self::InvalidOpLog => "invalid-op-log",
498            Self::SavedNotRebased => "saved-not-rebased",
499            Self::NoPendingSave => "no-pending-save",
500            Self::MalformedXmp => "malformed-xmp",
501            Self::UnknownSource => "unknown-source",
502            Self::OpenActionNotDestination => "open-action-not-destination",
503            Self::UnknownOutlineItem => "unknown-outline-item",
504            Self::DirectOutlineItem => "direct-outline-item",
505            Self::OutlineNotASibling => "outline-not-a-sibling",
506            Self::OutlineMoveIntoItself => "outline-move-into-itself",
507            Self::UnknownNamedDestination => "unknown-named-destination",
508            Self::NamedDestinationExists => "named-destination-exists",
509            Self::EmptyDestinationName => "empty-destination-name",
510            Self::LinkUriRefused => "link-uri-refused",
511            Self::ViewNotFinite => "view-not-finite",
512            Self::XmpClaimReadOnly => "xmp-claim-read-only",
513            Self::InvalidXmpPacket => "invalid-xmp-packet",
514            Self::InvalidXmpProperty => "invalid-xmp-property",
515            Self::NoPagesLeft => "no-pages-left",
516            Self::InvalidOp => "invalid-op",
517            Self::UnknownAnnotation => "unknown-annotation",
518            Self::AnnotationLocked => "annotation-locked",
519            Self::AnnotationNotEditable => "annotation-not-editable",
520            Self::NotALink => "not-a-link",
521            Self::LinkNotTagged => "link-not-tagged",
522            Self::AppearanceUnavailable => "appearance-unavailable",
523            Self::InvalidLabelRanges => "invalid-label-ranges",
524            Self::Sink => "sink",
525            Self::NotRebased => "not-rebased",
526            Self::SinkNotEmpty => "sink-not-empty",
527            Self::WouldInvalidateSignatures => "would-invalidate-signatures",
528            Self::RequiresRewrite => "requires-rewrite",
529            Self::InvalidFont => "invalid-font",
530            Self::CollectionIndex => "collection-index",
531            Self::UnknownAxis => "unknown-axis",
532            Self::FontNotEmbeddable => "font-not-embeddable",
533            Self::MissingGlyph => "missing-glyph",
534            Self::GlyphOutOfRange => "glyph-out-of-range",
535            Self::UnknownFont => "unknown-font",
536            Self::SubsetFailed => "subset-failed",
537            Self::InvalidAxisValue => "invalid-axis-value",
538            Self::WrongDocument => "wrong-document",
539            Self::InvalidFeature => "invalid-feature",
540            Self::InvalidTextRange => "invalid-text-range",
541            Self::InvalidSpans => "invalid-spans",
542            Self::UnsupportedLayoutOption => "unsupported-layout-option",
543            Self::FontMismatch => "font-mismatch",
544            Self::EncodingFull => "encoding-full",
545            Self::FontNotShapable => "font-not-shapable",
546            Self::InvalidImage => "invalid-image",
547            Self::UnsupportedImage => "unsupported-image",
548            Self::ImageTooLarge => "image-too-large",
549            Self::ImageDataLength => "image-data-length",
550            Self::InvalidIccProfile => "invalid-icc-profile",
551            Self::ColorComponents => "color-components",
552            Self::InvalidColor => "invalid-color",
553            Self::InvalidGeometry => "invalid-geometry",
554            Self::TextOverflow => "text-overflow",
555            Self::PageIndexOutOfRange => "page-index-out-of-range",
556            Self::UnknownDestination => "unknown-destination",
557            Self::InvalidPageLabels => "invalid-page-labels",
558            Self::TagElementNotOpen => "tag-element-not-open",
559            Self::TagElementUnclosed => "tag-element-unclosed",
560            Self::ProfileVersionConflict => "profile-version-conflict",
561            Self::MissingTitle => "missing-title",
562            Self::MissingLang => "missing-lang",
563            Self::MissingAltText => "missing-alt-text",
564            Self::UntaggedContent => "untagged-content",
565            Self::HeadingLevelSkipped => "heading-level-skipped",
566            Self::UnnumberedHeadingMisused => "unnumbered-heading-misused",
567            Self::InvalidStructureNesting => "invalid-structure-nesting",
568            Self::LinkWithoutStructure => "link-without-structure",
569            Self::LinkWithoutContents => "link-without-contents",
570            Self::FontNotEmbedded => "font-not-embedded",
571            Self::GlyphWithoutUnicode => "glyph-without-unicode",
572            Self::DeviceColorWithoutOutputIntent => "device-color-without-output-intent",
573            Self::EmbeddedFileForbidden => "embedded-file-forbidden",
574            Self::EmbeddedFileWithoutMimeType => "embedded-file-without-mime-type",
575            Self::FlowContentTooLarge => "flow-content-too-large",
576            Self::FlowLayoutUnstable => "flow-layout-unstable",
577            Self::InvalidDocument => "invalid-document",
578            Self::TemplateDataMissing => "template-data-missing",
579            Self::TemplateDataType => "template-data-type",
580            Self::TemplateTooLarge => "template-too-large",
581            Self::RenderTooLarge => "render-too-large",
582            Self::RenderFailed => "render-failed",
583            Self::RenderBackendUnavailable => "render-backend-unavailable",
584            Self::ExportFailed => "export-failed",
585            Self::ModelFailed => "model-failed",
586            Self::ModelResultUnexpected => "model-result-unexpected",
587            Self::ModelNeedsHost => "model-needs-host",
588            Self::Cancelled => "cancelled",
589            Self::JobFinished => "job-finished",
590            Self::DocumentChanged => "document-changed",
591            Self::RevisionIndexOutOfRange => "revision-index-out-of-range",
592            Self::BuilderFinished => "builder-finished",
593            Self::Disposed => "disposed",
594            Self::InvalidArgument => "invalid-argument",
595            Self::SourceBudgetExceeded => "source-budget-exceeded",
596            Self::UnknownOption => "unknown-option",
597            Self::InvalidCommandLine => "invalid-command-line",
598            Self::InvalidPageRange => "invalid-page-range",
599            Self::BinaryOutputToTerminal => "binary-output-to-terminal",
600            Self::UnknownCode => "unknown-code",
601            Self::OverwriteRefused => "overwrite-refused",
602            Self::InputUnreadable => "input-unreadable",
603            Self::OutputUnwritable => "output-unwritable",
604            Self::PathOutsideRoots => "path-outside-roots",
605        }
606    }
607
608    /// The kind (ADR 0026 §2).
609    ///
610    /// Added in 0.2.0.
611    #[must_use]
612    pub const fn kind(self) -> ErrorKind {
613        match self {
614            Self::NotPdf => ErrorKind::Input,
615            Self::MissingRoot => ErrorKind::Input,
616            Self::ReferenceCycle => ErrorKind::Input,
617            Self::LimitExceeded => ErrorKind::Limit,
618            Self::Strict => ErrorKind::Input,
619            Self::DataPending => ErrorKind::State,
620            Self::Source => ErrorKind::Io,
621            Self::Type => ErrorKind::Input,
622            Self::InvalidStructure => ErrorKind::Input,
623            Self::UnsetObject => ErrorKind::Internal,
624            Self::RepairedBase => ErrorKind::State,
625            Self::EncryptedBase => ErrorKind::Unsupported,
626            Self::PasswordRequired => ErrorKind::Security,
627            Self::WrongPassword => ErrorKind::Security,
628            Self::UnsupportedSecurityHandler => ErrorKind::Unsupported,
629            Self::UnexpectedEof => ErrorKind::Input,
630            Self::Syntax => ErrorKind::Input,
631            Self::UnsupportedFilter => ErrorKind::Unsupported,
632            Self::Decompress => ErrorKind::Input,
633            Self::NestedTransaction => ErrorKind::State,
634            Self::NoTransaction => ErrorKind::State,
635            Self::UnknownPage => ErrorKind::Usage,
636            Self::DirectPage => ErrorKind::Unsupported,
637            Self::UnsupportedVersion => ErrorKind::Unsupported,
638            Self::InvalidOpLog => ErrorKind::Input,
639            Self::SavedNotRebased => ErrorKind::State,
640            Self::NoPendingSave => ErrorKind::State,
641            Self::MalformedXmp => ErrorKind::Input,
642            Self::UnknownSource => ErrorKind::Usage,
643            Self::OpenActionNotDestination => ErrorKind::Usage,
644            Self::UnknownOutlineItem => ErrorKind::Usage,
645            Self::DirectOutlineItem => ErrorKind::Unsupported,
646            Self::OutlineNotASibling => ErrorKind::Usage,
647            Self::OutlineMoveIntoItself => ErrorKind::Usage,
648            Self::UnknownNamedDestination => ErrorKind::Usage,
649            Self::NamedDestinationExists => ErrorKind::Usage,
650            Self::EmptyDestinationName => ErrorKind::Usage,
651            Self::LinkUriRefused => ErrorKind::Usage,
652            Self::ViewNotFinite => ErrorKind::Usage,
653            Self::XmpClaimReadOnly => ErrorKind::Usage,
654            Self::InvalidXmpPacket => ErrorKind::Input,
655            Self::InvalidXmpProperty => ErrorKind::Usage,
656            Self::NoPagesLeft => ErrorKind::Usage,
657            Self::InvalidOp => ErrorKind::Usage,
658            Self::UnknownAnnotation => ErrorKind::Usage,
659            Self::AnnotationLocked => ErrorKind::State,
660            Self::AnnotationNotEditable => ErrorKind::Unsupported,
661            Self::NotALink => ErrorKind::Usage,
662            Self::LinkNotTagged => ErrorKind::Unsupported,
663            Self::AppearanceUnavailable => ErrorKind::Unsupported,
664            Self::InvalidLabelRanges => ErrorKind::Usage,
665            Self::Sink => ErrorKind::Io,
666            Self::NotRebased => ErrorKind::State,
667            Self::SinkNotEmpty => ErrorKind::Usage,
668            Self::WouldInvalidateSignatures => ErrorKind::Security,
669            Self::RequiresRewrite => ErrorKind::State,
670            Self::InvalidFont => ErrorKind::Input,
671            Self::CollectionIndex => ErrorKind::Usage,
672            Self::UnknownAxis => ErrorKind::Usage,
673            Self::FontNotEmbeddable => ErrorKind::Usage,
674            Self::MissingGlyph => ErrorKind::Input,
675            Self::GlyphOutOfRange => ErrorKind::Usage,
676            Self::UnknownFont => ErrorKind::Usage,
677            Self::SubsetFailed => ErrorKind::Unsupported,
678            Self::InvalidAxisValue => ErrorKind::Usage,
679            Self::WrongDocument => ErrorKind::Usage,
680            Self::InvalidFeature => ErrorKind::Usage,
681            Self::InvalidTextRange => ErrorKind::Usage,
682            Self::InvalidSpans => ErrorKind::Usage,
683            Self::UnsupportedLayoutOption => ErrorKind::Unsupported,
684            Self::FontMismatch => ErrorKind::Usage,
685            Self::EncodingFull => ErrorKind::Limit,
686            Self::FontNotShapable => ErrorKind::Unsupported,
687            Self::InvalidImage => ErrorKind::Input,
688            Self::UnsupportedImage => ErrorKind::Unsupported,
689            Self::ImageTooLarge => ErrorKind::Limit,
690            Self::ImageDataLength => ErrorKind::Usage,
691            Self::InvalidIccProfile => ErrorKind::Input,
692            Self::ColorComponents => ErrorKind::Usage,
693            Self::InvalidColor => ErrorKind::Usage,
694            Self::InvalidGeometry => ErrorKind::Usage,
695            Self::TextOverflow => ErrorKind::Usage,
696            Self::PageIndexOutOfRange => ErrorKind::Usage,
697            Self::UnknownDestination => ErrorKind::Usage,
698            Self::InvalidPageLabels => ErrorKind::Usage,
699            Self::TagElementNotOpen => ErrorKind::Usage,
700            Self::TagElementUnclosed => ErrorKind::Usage,
701            Self::ProfileVersionConflict => ErrorKind::Usage,
702            Self::MissingTitle => ErrorKind::Usage,
703            Self::MissingLang => ErrorKind::Usage,
704            Self::MissingAltText => ErrorKind::Usage,
705            Self::UntaggedContent => ErrorKind::Usage,
706            Self::HeadingLevelSkipped => ErrorKind::Usage,
707            Self::UnnumberedHeadingMisused => ErrorKind::Usage,
708            Self::InvalidStructureNesting => ErrorKind::Usage,
709            Self::LinkWithoutStructure => ErrorKind::Usage,
710            Self::LinkWithoutContents => ErrorKind::Usage,
711            Self::FontNotEmbedded => ErrorKind::Usage,
712            Self::GlyphWithoutUnicode => ErrorKind::Usage,
713            Self::DeviceColorWithoutOutputIntent => ErrorKind::Usage,
714            Self::EmbeddedFileForbidden => ErrorKind::Usage,
715            Self::EmbeddedFileWithoutMimeType => ErrorKind::Usage,
716            Self::FlowContentTooLarge => ErrorKind::Usage,
717            Self::FlowLayoutUnstable => ErrorKind::Internal,
718            Self::InvalidDocument => ErrorKind::Usage,
719            Self::TemplateDataMissing => ErrorKind::Usage,
720            Self::TemplateDataType => ErrorKind::Usage,
721            Self::TemplateTooLarge => ErrorKind::Usage,
722            Self::RenderTooLarge => ErrorKind::Limit,
723            Self::RenderFailed => ErrorKind::Input,
724            Self::RenderBackendUnavailable => ErrorKind::Io,
725            Self::ExportFailed => ErrorKind::Internal,
726            Self::ModelFailed => ErrorKind::Internal,
727            Self::ModelResultUnexpected => ErrorKind::Usage,
728            Self::ModelNeedsHost => ErrorKind::Usage,
729            Self::Cancelled => ErrorKind::Cancelled,
730            Self::JobFinished => ErrorKind::State,
731            Self::DocumentChanged => ErrorKind::State,
732            Self::RevisionIndexOutOfRange => ErrorKind::Usage,
733            Self::BuilderFinished => ErrorKind::State,
734            Self::Disposed => ErrorKind::State,
735            Self::InvalidArgument => ErrorKind::Usage,
736            Self::SourceBudgetExceeded => ErrorKind::Limit,
737            Self::UnknownOption => ErrorKind::Usage,
738            Self::InvalidCommandLine => ErrorKind::Usage,
739            Self::InvalidPageRange => ErrorKind::Usage,
740            Self::BinaryOutputToTerminal => ErrorKind::Usage,
741            Self::UnknownCode => ErrorKind::Usage,
742            Self::OverwriteRefused => ErrorKind::State,
743            Self::InputUnreadable => ErrorKind::Io,
744            Self::OutputUnwritable => ErrorKind::Io,
745            Self::PathOutsideRoots => ErrorKind::Security,
746        }
747    }
748
749    /// One lowercase sentence: what happened.
750    ///
751    /// Added in 0.2.0.
752    #[must_use]
753    pub const fn summary(self) -> &'static str {
754        match self {
755            Self::NotPdf => "the input does not look like a PDF at all",
756            Self::MissingRoot => "no document catalog (/Root) was found, even after repair",
757            Self::ReferenceCycle => "a reference chain or the page tree loops back on itself",
758            Self::LimitExceeded => "a hard Limits value was exceeded",
759            Self::Strict => "strict mode refused something the tolerant reader would have repaired",
760            Self::DataPending => "the ByteSource has not fetched the byte ranges the call needs yet",
761            Self::Source => "the ByteSource failed to read",
762            Self::Type => "an object had a different type than the structure requires",
763            Self::InvalidStructure => "an object stream, xref section or filter parameter was malformed",
764            Self::UnsetObject => "a writer object number was reserved but never given a value",
765            Self::RepairedBase => "an incremental update was requested for a document whose xref needed repair",
766            Self::EncryptedBase => "a save of an encrypted document was requested",
767            Self::PasswordRequired => "the document is encrypted with a user password and none was given",
768            Self::WrongPassword => "the given password is neither the user nor the owner password",
769            Self::UnsupportedSecurityHandler => "the document uses a security handler Lamina PDF cannot decrypt",
770            Self::UnexpectedEof => "the input ended before a complete token or object was read",
771            Self::Syntax => "a token or structure did not match the PDF grammar",
772            Self::UnsupportedFilter => "a stream uses a filter Lamina PDF does not implement",
773            Self::Decompress => "compressed stream data was corrupt",
774            Self::NestedTransaction => "a transaction was started, or undo or redo called, while one is open",
775            Self::NoTransaction => "apply, commit or rollback was called without an open transaction",
776            Self::UnknownPage => "an op names a page the document does not have",
777            Self::DirectPage => "the page is a direct dictionary, which ops cannot edit yet",
778            Self::UnsupportedVersion => "an op log has a schema version this reader does not know",
779            Self::InvalidOpLog => "an op log does not parse: an unknown op or field, a bad value, or not JSON",
780            Self::SavedNotRebased => "the document was saved to a sink Lamina PDF cannot read back and waits for rebase",
781            Self::NoPendingSave => "rebase was called without a save waiting for it",
782            Self::MalformedXmp => "a metadata edit would replace the document's XMP packet, which can't be read, losing what it holds",
783            Self::UnknownSource => "an op or a call names a source document that was not added to the session",
784            Self::OpenActionNotDestination => "an op would replace or remove the document's open action, which is an action other than a destination",
785            Self::UnknownOutlineItem => "an outline op names a bookmark the outline does not have",
786            Self::DirectOutlineItem => "the bookmark is stored inside another item rather than as an object of its own, so outline ops can't name it yet",
787            Self::OutlineNotASibling => "the position names a bookmark that is not a child of the parent the op names",
788            Self::OutlineMoveIntoItself => "a move would put a bookmark inside itself or one of its descendants",
789            Self::UnknownNamedDestination => "the op names a destination the file does not define",
790            Self::NamedDestinationExists => "a rename to a name another destination already has",
791            Self::EmptyDestinationName => "a destination name is empty",
792            Self::LinkUriRefused => "a web address that isn't an absolute http, https or mailto address in plain ASCII",
793            Self::ViewNotFinite => "a destination's coordinates and zoom must be finite numbers",
794            Self::XmpClaimReadOnly => "an XMP edit would change the file's PDF/A or PDF/UA identification, which only conversion or a check may set",
795            Self::InvalidXmpPacket => "the XMP packet given to replace the document's doesn't parse",
796            Self::InvalidXmpProperty => "an XMP property edit names a property, or gives a value, that can't be written",
797            Self::NoPagesLeft => "a page deletion would leave the document with no pages",
798            Self::InvalidOp => "an op's values are out of range, such as a page count or a page size",
799            Self::UnknownAnnotation => "the op names an annotation that no page of the document lists",
800            Self::AnnotationLocked => "the annotation's flags forbid the change: Locked forbids deleting it or changing its properties, LockedContents changing its contents",
801            Self::AnnotationNotEditable => "the annotation can't be edited by the annotation ops: it is a form field's widget, or a direct dictionary with no object of its own",
802            Self::NotALink => "a link op names an annotation that isn't a link",
803            Self::LinkNotTagged => "the file claims PDF/UA-1 but has no structure tree for a new link to join",
804            Self::AppearanceUnavailable => "the document has no appearance generator, so it can't draw a new annotation",
805            Self::InvalidLabelRanges => "page label ranges whose first isn't on the first page, that are out of page order or share a page, or that number from 0",
806            Self::Sink => "the sink failed to take the bytes or could not give them back",
807            Self::NotRebased => "the output was written, but rebasing the document onto it failed",
808            Self::SinkNotEmpty => "the sink already held bytes before the save started",
809            Self::WouldInvalidateSignatures => "the save would break one or more signatures",
810            Self::RequiresRewrite => "an incremental save was requested but only a full rewrite is safe",
811            Self::InvalidFont => "font bytes could not be read as a font",
812            Self::CollectionIndex => "a font collection member past the end of the collection was asked for",
813            Self::UnknownAxis => "an instance was asked for on a variation axis the font does not have",
814            Self::FontNotEmbeddable => "the font's OS/2 fsType forbids embedding",
815            Self::MissingGlyph => "the font has no glyph for a character of the text",
816            Self::GlyphOutOfRange => "a glyph ID at or past the font's glyph count was used",
817            Self::UnknownFont => "a FontKey was used with a registry that did not hand it out",
818            Self::SubsetFailed => "subsetting a font failed",
819            Self::InvalidAxisValue => "a variation axis value was NaN or infinite",
820            Self::WrongDocument => "finish_fonts was given a document the registry did not reserve its fonts in",
821            Self::InvalidFeature => "an OpenType feature setting did not parse",
822            Self::InvalidTextRange => "a byte range was out of bounds or not on character boundaries of the text",
823            Self::InvalidSpans => "the styled spans given for a paragraph do not cover its text once, in order",
824            Self::UnsupportedLayoutOption => "a layout option that is not implemented yet was asked for",
825            Self::FontMismatch => "a shaped run was given with a font key for a different font than it was shaped with",
826            Self::EncodingFull => "a standard 14 font has no free one-byte code left for another glyph",
827            Self::FontNotShapable => "a standard 14 font was given to shaping or layout, which need a font program",
828            Self::InvalidImage => "image bytes are not a readable image of the format they were given as",
829            Self::UnsupportedImage => "the image uses a feature that PDF or Lamina PDF does not support",
830            Self::ImageTooLarge => "the image needs more memory than the builder allows (a decoded PNG over 256 MiB, or raw dimensions whose size overflows)",
831            Self::ImageDataLength => "raw image samples are not width x height x channels bytes long",
832            Self::InvalidIccProfile => "the bytes are not a usable ICC profile",
833            Self::ColorComponents => "a colour has the wrong number of components for its colour space",
834            Self::InvalidColor => "a colour string is not of the form #rgb or #rrggbb",
835            Self::InvalidGeometry => "a page size, box, /UserUnit, drawing value (coordinate, matrix, line width, dash, miter limit) or image size is not usable",
836            Self::TextOverflow => "a text box's lines don't all fit its height and its options asked for an error",
837            Self::PageIndexOutOfRange => "a link, outline item or destination names a page index the document doesn't have",
838            Self::UnknownDestination => "a link or outline item names a destination that was never defined",
839            Self::InvalidPageLabels => "page label ranges that don't start at page 0, don't increase, start past the last page or number from 0",
840            Self::TagElementNotOpen => "a structure element resumed or closed isn't open",
841            Self::TagElementUnclosed => "structure elements opened across pages were never closed",
842            Self::ProfileVersionConflict => "the PDF version asked for is one the profile doesn't allow (PDF/UA-1, PDF/A-2 and PDF/A-3 are based on PDF 1.7)",
843            Self::MissingTitle => "PDF/UA-1 needs a document title, and the metadata gives none",
844            Self::MissingLang => "PDF/UA-1 needs the document's natural language, and none was set",
845            Self::MissingAltText => "a Figure or Formula has no alternate text (/Alt or /ActualText), which PDF/UA-1 requires",
846            Self::UntaggedContent => "content was drawn outside every structure element and artifact, which PDF/UA-1 forbids",
847            Self::HeadingLevelSkipped => "a heading skips a level (the first is not H1, or an H3 follows an H1), which PDF/UA-1 forbids",
848            Self::UnnumberedHeadingMisused => "an unnumbered H heading shares its parent with another H, or the document also uses H1-H6, which PDF/UA-1 forbids",
849            Self::InvalidStructureNesting => "a table or list element sits in a parent its type doesn't allow (a TD outside a TR, a P directly in a Table)",
850            Self::LinkWithoutStructure => "a link annotation has no Link structure element (it was drawn inside an artifact), which PDF/UA-1 forbids",
851            Self::LinkWithoutContents => "a link annotation has no description (/Contents), which PDF/UA-1 requires",
852            Self::FontNotEmbedded => "a standard 14 font, which is never embedded, was used under a profile that needs every font embedded",
853            Self::GlyphWithoutUnicode => "a glyph was drawn without a Unicode value, which PDF/A-2u and PDF/UA-1 forbid",
854            Self::DeviceColorWithoutOutputIntent => "a DeviceCMYK colour or image was used, but the PDF/A output intent is sRGB",
855            Self::EmbeddedFileForbidden => "PDF/A-2 doesn't allow attached files that aren't PDF/A themselves",
856            Self::EmbeddedFileWithoutMimeType => "an attached file has no MIME type, which every PDF/A profile requires",
857            Self::FlowContentTooLarge => "a line or a figure of a flow is taller than the page's body, so no page can hold it",
858            Self::FlowLayoutUnstable => "a flow's contents page kept changing its page numbers after four layouts",
859            Self::InvalidDocument => "a laminapdf.document/1 document has an unknown key, a missing one or a value of the wrong kind",
860            Self::TemplateDataMissing => "a template's $data, $each or $item points to a value the data doesn't have",
861            Self::TemplateDataType => "a template's placeholder found data of the wrong kind: $each over something that isn't a list, or text from an object",
862            Self::TemplateTooLarge => "a template would fill in more values, or nest deeper, than a document may hold",
863            Self::RenderTooLarge => "the requested tile is larger than the render limits allow; nothing was allocated",
864            Self::RenderFailed => "the render engine could not open the document or draw the page",
865            Self::RenderBackendUnavailable => "the render engine is not available: its library or module could not be loaded",
866            Self::ExportFailed => "an export's PNG, JPEG or TIFF encoder failed on a page that was drawn",
867            Self::ModelFailed => "a layout model, OCR engine or page renderer plugged into an extraction failed; the extraction stops with no partial result",
868            Self::ModelResultUnexpected => "a model result was handed to an extraction job that hadn't asked for it, or was the other model's result",
869            Self::ModelNeedsHost => "an extraction in one call was given a model whose results only the host can give: a host model, or a plug-in model without a page renderer",
870            Self::Cancelled => "a CancelToken stopped the work; the job is finished and returned no partial result",
871            Self::JobFinished => "a job was stepped after it had finished, failed or been cancelled",
872            Self::DocumentChanged => "the document a job was created for changed (an edit, undo, redo, save or rebase) or a different document was passed to step",
873            Self::RevisionIndexOutOfRange => "an earlier revision was asked for by an index past the file's last revision",
874            Self::BuilderFinished => "a builder or one of its pages was used after it finished",
875            Self::Disposed => "a document, builder or other handle was used after free(), or after the using block that held it ended",
876            Self::InvalidArgument => "a value passed to a binding does not have the shape its type declares",
877            Self::SourceBudgetExceeded => "a sparse source was given more bytes than its byte budget allows",
878            Self::UnknownOption => "an options record passed to a binding has a key Lamina PDF does not know",
879            Self::InvalidCommandLine => "the command line doesn't parse: an unknown command or flag, a missing argument, a bad value, or stdin named twice",
880            Self::InvalidPageRange => "a page range doesn't fit the grammar, or names a page the document lacks",
881            Self::BinaryOutputToTerminal => "the command would write a PDF to standard output, and standard output is a terminal",
882            Self::UnknownCode => "explain was given a code that isn't a Lamina PDF error or warning code",
883            Self::OverwriteRefused => "the output file exists, or the command would modify its input in place, and --force wasn't given",
884            Self::InputUnreadable => "an input file, standard input or the password file couldn't be read",
885            Self::OutputUnwritable => "the output couldn't be written: its folder is missing or read-only, the disk is full, or standard output closed",
886            Self::PathOutsideRoots => "laminapdf mcp was given a path outside its --root folders, or a link that leads out of them",
887        }
888    }
889
890    /// The hint (ADR 0026 §5), with its `{limit}`/`{option}` parameters unfilled.
891    ///
892    /// Added in 0.2.0.
893    #[must_use]
894    pub const fn hint(self) -> &'static str {
895        match self {
896            Self::NotPdf => "check that the bytes passed to open are a PDF file",
897            Self::MissingRoot => "use another copy of the file: this one has no usable catalog",
898            Self::ReferenceCycle => "use another copy of the file, or repair it with another tool",
899            Self::LimitExceeded => "the input exceeds a safety limit; raise {limit} in Limits only if you trust the input",
900            Self::Strict => "open without strict mode to read the file with repairs, or fix the file",
901            Self::DataPending => "fetch the listed ranges into the source and retry the call",
902            Self::Source => "retry the call, or check the source; the document stays usable",
903            Self::Type => "use another copy of the file, or repair it with another tool",
904            Self::InvalidStructure => "use another copy of the file, or repair it with another tool",
905            Self::UnsetObject => "this is a bug in Lamina PDF: report it with the steps that led to it",
906            Self::RepairedBase => "save with a full rewrite instead of an incremental update",
907            Self::EncryptedBase => "saving encrypted documents is not supported yet; use another tool to decrypt or re-encrypt",
908            Self::PasswordRequired => "pass the document's password in OpenOptions",
909            Self::WrongPassword => "ask for the password again and retry with the correct one",
910            Self::UnsupportedSecurityHandler => "use a tool that supports this encryption to decrypt the file first",
911            Self::UnexpectedEof => "use a complete copy of the file: this one looks truncated",
912            Self::Syntax => "use another copy of the file, or repair it with another tool",
913            Self::UnsupportedFilter => "use a tool that supports the filter to read this stream",
914            Self::Decompress => "use another copy of the file: this stream's data is damaged",
915            Self::NestedTransaction => "commit or roll back the open transaction first, or use a savepoint inside it",
916            Self::NoTransaction => "call begin first, or use transact",
917            Self::UnknownPage => "use a PageId from this document's pages()",
918            Self::DirectPage => "rewrite the file so that every page is an indirect object, or wait for page-structure ops",
919            Self::UnsupportedVersion => "upgrade Lamina PDF to a version that reads this op log version",
920            Self::InvalidOpLog => "validate the op log against the op schema; the samples in fixtures/ops show the format",
921            Self::SavedNotRebased => "call rebase with the saved bytes before applying ops or saving again",
922            Self::NoPendingSave => "call rebase only after a save that returned SavedNotRebased",
923            Self::MalformedXmp => "set replaceMalformed on the edit to replace the packet with a new one, or leave the metadata as it is",
924            Self::UnknownSource => "add the source document's bytes with addSource before applying ops that name it",
925            Self::OpenActionNotDestination => "leave the open page out of the edit, which keeps the open action as it is",
926            Self::UnknownOutlineItem => "read the outline again and use one of its item IDs; an item a previous op deleted is gone",
927            Self::DirectOutlineItem => "apply any other outline op first: it rewrites the outline and gives every bookmark an object and an ID of its own",
928            Self::OutlineNotASibling => "name a position among the parent's own children, or use first or last",
929            Self::OutlineMoveIntoItself => "choose a parent outside the bookmark's own branch",
930            Self::UnknownNamedDestination => "list the file's named destinations and use one of their names",
931            Self::NamedDestinationExists => "choose a name no destination has, or delete the other one first",
932            Self::EmptyDestinationName => "give the destination a name of at least one character",
933            Self::LinkUriRefused => "use a full address such as https://example.com/page; encode other characters with %",
934            Self::ViewNotFinite => "pass finite numbers, or null to keep the viewer's current value",
935            Self::XmpClaimReadOnly => "leave the pdfaid: and pdfuaid: properties as they are; edit the other properties, or keep them unchanged in a replaced packet",
936            Self::InvalidXmpPacket => "fix the XML at the offset in the error's data (reason says what is wrong), then replace the packet again",
937            Self::InvalidXmpProperty => "check the part the error's reason names: the namespace, prefix, name, value, or the shape a mirrored property needs",
938            Self::NoPagesLeft => "keep at least one page: delete all but one, or insert a blank page first",
939            Self::InvalidOp => "insert between 1 and 10,000 pages at a time, each with a width and height above 0 and up to 14,400 points",
940            Self::UnknownAnnotation => "read the page's annotations again and use an ID from that list",
941            Self::AnnotationLocked => "clear the lock with an update of its flags first, if you may",
942            Self::AnnotationNotEditable => "edit a widget through its form field; an annotation stored inside the page's list can't be edited yet",
943            Self::NotALink => "name a link from the page's links; change other annotations with updateAnnot and deleteAnnot",
944            Self::LinkNotTagged => "tag the document first, or add the link to a copy that doesn't claim PDF/UA",
945            Self::AppearanceUnavailable => "edit through the laminapdf crate, which draws appearances, or give laminapdf-ops a generator with Document::with_appearances",
946            Self::InvalidLabelRanges => "give ranges in page order, the first on the document's first page, each numbered from 1 or more",
947            Self::Sink => "check the destination and retry the save; the document is unchanged",
948            Self::NotRebased => "retry rebase with the saved output carried by the error",
949            Self::SinkNotEmpty => "pass an empty sink: output offsets count from the sink's first byte",
950            Self::WouldInvalidateSignatures => "save with SaveMode::Auto, or ask the user and retry with SaveOptions::with_invalidate_signatures",
951            Self::RequiresRewrite => "save with SaveMode::Auto or SaveMode::FullRewrite",
952            Self::InvalidFont => "pass the complete bytes of a .ttf, .otf, .ttc or .otc file",
953            Self::CollectionIndex => "use an index below Font::collection_len",
954            Self::UnknownAxis => "check the font's axes before choosing coordinates, or use a variable font",
955            Self::FontNotEmbeddable => "use another font, or register it with EmbedPolicy::Override if your licence allows embedding",
956            Self::MissingGlyph => "use a font that covers the character, or split the text across fonts",
957            Self::GlyphOutOfRange => "pass glyph IDs from the font you registered",
958            Self::UnknownFont => "use the key returned by this registry's add",
959            Self::SubsetFailed => "try another version or format of the font, and report the font if it is a common one",
960            Self::InvalidAxisValue => "pass finite axis values; values outside the axis range are clamped",
961            Self::WrongDocument => "use one FontRegistry per document and finish it with that document",
962            Self::InvalidFeature => "write it as liga=0, -liga, smcp or aalt=2 (HarfBuzz syntax without ranges)",
963            Self::InvalidTextRange => "take ranges from Lamina PDF's results (line_breaks, itemize, break_lines) and pass the same text",
964            Self::InvalidSpans => "give spans in text order, each starting where the one before ends, from byte 0 to the end of the text, between grapheme clusters, each with at least one font from the list",
965            Self::UnsupportedLayoutOption => "leave the option at its default; justification comes with a later release",
966            Self::FontMismatch => "pass the key of the font the run was shaped with (the font index of each line run maps to your keys)",
967            Self::EncodingFull => "embed a font with Font::from_bytes, or split the text across two registrations of the standard font",
968            Self::FontNotShapable => "draw standard 14 fonts with FontRegistry::encode, or shape with an embedded font",
969            Self::InvalidImage => "pass the complete bytes of a JPEG or PNG file to Image::jpeg or Image::png",
970            Self::UnsupportedImage => "convert it to a baseline or progressive 8-bit JPEG, or to PNG",
971            Self::ImageTooLarge => "scale the image down before adding it",
972            Self::ImageDataLength => "pass exactly 4 bytes (RGBA) per pixel, row by row",
973            Self::InvalidIccProfile => "pass a complete ICC profile with a Gray, RGB or CMYK data colour space",
974            Self::ColorComponents => "give one component per channel of the colour space (/N of the ICC profile)",
975            Self::InvalidColor => "write the colour as # followed by 3 or 6 hexadecimal digits",
976            Self::InvalidGeometry => "use finite coordinates, positive page sizes and /UserUnit, non-negative line widths and dashes, a miter limit of at least 1, and images of at least one pixel",
977            Self::TextOverflow => "make the box taller or the text shorter, or use Overflow::Clip and read TextLayout::overflow",
978            Self::PageIndexOutOfRange => "use a 0-based index below the document's page count",
979            Self::UnknownDestination => "define it with Builder::destination before the build finishes, or link to a page",
980            Self::InvalidPageLabels => "give ranges sorted by first page, the first at page 0, numbered from 1",
981            Self::TagElementNotOpen => "resume and close only elements this builder's pages opened with open_element, and close each once",
982            Self::TagElementUnclosed => "close each element from open_element with Builder::close_element once its last page is finished",
983            Self::ProfileVersionConflict => "leave the version at 1.7 (the default) or lower; PDF 2.0 needs PDF/A-4 or PDF/UA-2, which Lamina PDF doesn't write yet",
984            Self::MissingTitle => "set a title with Builder::metadata (Metadata::with_title)",
985            Self::MissingLang => "set the language with Builder::lang, such as \"en-GB\"",
986            Self::MissingAltText => "give the figure or formula a description with Tag::with_alt or Surface::figure's alt, or draw decoration as an artifact",
987            Self::UntaggedContent => "draw it inside Surface::tag (real content) or Surface::artifact (decoration)",
988            Self::HeadingLevelSkipped => "start with H1 and go down one level at a time",
989            Self::UnnumberedHeadingMisused => "use numbered headings (H1, H2, ...) throughout, or one H per section",
990            Self::InvalidStructureNesting => "nest tables as Table > TR > TH/TD and lists as L > LI > Lbl/LBody",
991            Self::LinkWithoutStructure => "draw links outside artifacts, so the builder gives each one a Link element",
992            Self::LinkWithoutContents => "pass a description as the link's contents",
993            Self::FontNotEmbedded => "load a font file with Builder::font instead of Builder::standard_font",
994            Self::GlyphWithoutUnicode => "remove NUL characters (U+0000) from the text, or choose PDF/A-2b, which doesn't need Unicode",
995            Self::DeviceColorWithoutOutputIntent => "use RGB or gray colours, or a CMYK colour with an ICC profile (Color::icc)",
996            Self::EmbeddedFileForbidden => "choose PDF/A-3b, which allows attached files of any kind",
997            Self::EmbeddedFileWithoutMimeType => "pass the file's MIME type, such as text/xml or application/octet-stream",
998            Self::FlowContentTooLarge => "make the figure smaller, the text size smaller or the page's margins narrower",
999            Self::FlowLayoutUnstable => "report the flow that fails; a page break after the contents block may avoid it until it is fixed",
1000            Self::InvalidDocument => "data.pointer names the value; correct it against the document schema, and didYouMean lists the closest known keys",
1001            Self::TemplateDataMissing => "data.pointer names the value the template asked for; add it to the data or correct the pointer",
1002            Self::TemplateDataType => "data.pointer names the value and data.expected the kind the template needs there",
1003            Self::TemplateTooLarge => "data.limit is the limit it passed; repeat fewer items, or split the document",
1004            Self::RenderTooLarge => "request smaller tiles (256 to 512 pixels at high zoom) or raise RenderLimits if the larger bitmap is intended",
1005            Self::RenderFailed => "the file may be damaged or use a feature this engine can't draw; try the other backend, or report the file",
1006            Self::RenderBackendUnavailable => "run cargo xtask fetch-pdfium or set LAMINA_PDF_PDFIUM_DIR to the folder holding the PDFium library",
1007            Self::ExportFailed => "report it with the format and the page: the encoder writes into memory, so this is a bug in Lamina PDF",
1008            Self::ModelFailed => "check the plug-in's own logs; extract without the model to get the rules-only result",
1009            Self::ModelResultUnexpected => "call provide only while request() returns a request, with the result its kind asks for",
1010            Self::ModelNeedsHost => "step an extraction job and hand it each result with provide, or give the plug-in a page renderer",
1011            Self::Cancelled => "nothing to do: this is the outcome the caller asked for; start a new job to try again",
1012            Self::JobFinished => "stop stepping a job once a step returned its result or an error; create a new job",
1013            Self::DocumentChanged => "pass the document the job was created from, and don't change it while the job runs; create a new job",
1014            Self::RevisionIndexOutOfRange => "ask for an index below the document's revision count",
1015            Self::BuilderFinished => "create a new builder or page: a finished one takes no more drawing, pages, fonts or settings",
1016            Self::Disposed => "free a handle only after its last use; to keep working, open the document again or create a new builder",
1017            Self::InvalidArgument => "pass the value the type declarations describe; the data field says what was wrong",
1018            Self::SourceBudgetExceeded => "raise the source's budget, or open the file with fewer bytes fetched (smaller blocks, no readahead)",
1019            Self::UnknownOption => "remove the key or correct its spelling; didYouMean lists the closest known names",
1020            Self::InvalidCommandLine => "run the command with --help to see its arguments",
1021            Self::InvalidPageRange => "write pages as 1-5, z for the last page, r2 for the second from the end, or x3 to leave page 3 out; data.position is the character where the range went wrong",
1022            Self::BinaryOutputToTerminal => "redirect standard output to a file or a pipe, or write to a file with -o",
1023            Self::UnknownCode => "check the spelling against didYouMean, or list every code at the docs URL",
1024            Self::OverwriteRefused => "pass --force, or write to a new file with -o",
1025            Self::InputUnreadable => "check that the file exists and that you can read it; data.input names it",
1026            Self::OutputUnwritable => "check that the output's folder exists, that you can write to it and that the disk has room",
1027            Self::PathOutsideRoots => "use a path inside one of the server's --root folders, or start the server with another --root",
1028        }
1029    }
1030
1031    /// The code's explain page (`docsUrl`, ADR 0026 §6).
1032    ///
1033    /// Added in 0.2.0.
1034    #[must_use]
1035    pub fn docs_url(self) -> String {
1036        format!("{DOCS_URL_BASE}{}{DOCS_URL_SUFFIX}", self.as_str())
1037    }
1038}
1039
1040/// Every warning code, in `codes.json` order.
1041///
1042/// Added in 0.2.0.
1043#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1044#[non_exhaustive]
1045pub enum WarningCode {
1046    /// `missing-header`: no %PDF-x.y header in the first 1,024 bytes; parsing went ahead.
1047    MissingHeader,
1048    /// `xref-repaired`: the stored cross-reference data was unusable and was rebuilt by scanning.
1049    XrefRepaired,
1050    /// `xrefstm-ignored`: a hybrid file's /XRefStm could not be read and was ignored.
1051    XrefstmIgnored,
1052    /// `stream-length-recovered`: a stream's /Length was wrong, so its end was found by scanning for endstream.
1053    StreamLengthRecovered,
1054    /// `dictionary-key-skipped`: a dictionary had something other than a name where a key belongs, and it was skipped.
1055    DictionaryKeySkipped,
1056    /// `stale-generation`: a reference's generation did not match its xref entry, so it resolved to null.
1057    StaleGeneration,
1058    /// `page-tree-node-skipped`: a page-tree node was missing, malformed or too deep, and was skipped.
1059    PageTreeNodeSkipped,
1060    /// `page-count-mismatch`: the page tree's /Count differs from the number of pages walked.
1061    PageCountMismatch,
1062    /// `flate-truncated`: Flate data was truncated or had a bad checksum; the partial output was kept.
1063    FlateTruncated,
1064    /// `filter-characters-skipped`: ASCIIHex or ASCII85 data held characters outside the filter's alphabet; they were skipped.
1065    FilterCharactersSkipped,
1066    /// `objstm-index-mismatch`: an object stream's index was stale and the object was found by searching.
1067    ObjstmIndexMismatch,
1068    /// `object-number-out-of-range`: an xref entry above max_object_number was dropped.
1069    ObjectNumberOutOfRange,
1070    /// `aes-padding-invalid`: AES-encrypted data had a bad length or padding and was kept as stored.
1071    AesPaddingInvalid,
1072    /// `perms-mismatch`: an R5/R6 document's /Perms does not match its /P and /EncryptMetadata.
1073    PermsMismatch,
1074    /// `warnings-truncated`: more than max_warnings warnings were raised and the rest were dropped.
1075    WarningsTruncated,
1076    /// `invalid-box`: a page boundary box is not four numbers and reads as absent.
1077    InvalidBox,
1078    /// `invalid-rotate`: a page's /Rotate is not a multiple of 90 and reads as 0.
1079    InvalidRotate,
1080    /// `name-tree-node-skipped`: a name- or number-tree node was malformed, repeated or too deep, and was skipped.
1081    NameTreeNodeSkipped,
1082    /// `outline-cycle`: an outline item was reached twice; that branch of the walk stopped.
1083    OutlineCycle,
1084    /// `outline-item-skipped`: an outline item was missing, not a dictionary or too deep, and was skipped with its subtree.
1085    OutlineItemSkipped,
1086    /// `invalid-date`: an Info date is not a valid PDF date; the raw string is kept.
1087    InvalidDate,
1088    /// `xmp-invalid`: the XMP metadata packet is not readable XMP and reads as absent.
1089    XmpInvalid,
1090    /// `annot-name-duplicate`: two annotations on one page have the same name (/NM), which should be unique on its page.
1091    AnnotNameDuplicate,
1092    /// `xmp-repaired`: the XMP metadata packet had damage other readers read past, and was read the same way.
1093    XmpRepaired,
1094    /// `invalid-page-label`: a /PageLabels entry is malformed; the malformed part is dropped.
1095    InvalidPageLabel,
1096    /// `invalid-entry`: an entry a view reads is unreadable or of the wrong type and reads as absent.
1097    InvalidEntry,
1098    /// `content-unknown-operator`: an operator the spec does not define was skipped outside a BX/EX section.
1099    ContentUnknownOperator,
1100    /// `content-bad-operands`: an operator had too few operands or operands of the wrong type, or extra ones.
1101    ContentBadOperands,
1102    /// `content-unbalanced-q`: a Q without a matching q was ignored, or saved graphics states were left open.
1103    ContentUnbalancedQ,
1104    /// `content-unbalanced-bt`: a text object was opened twice, closed outside one, or left open.
1105    ContentUnbalancedBt,
1106    /// `content-unbalanced-marked`: an EMC without a matching BMC or BDC was ignored, or marked content was left open.
1107    ContentUnbalancedMarked,
1108    /// `content-syntax`: content-stream bytes that are not a token were skipped.
1109    ContentSyntax,
1110    /// `content-resource-missing`: an operator named a resource that is missing, of the wrong type or unreadable.
1111    ContentResourceMissing,
1112    /// `inline-image-unterminated`: no EI ends an inline image; the rest of the content was skipped.
1113    InlineImageUnterminated,
1114    /// `xobject-cycle`: a Form XObject draws itself, directly or through other forms.
1115    XobjectCycle,
1116    /// `content-path-unpainted`: a content stream ended with a path no painting operator ended.
1117    ContentPathUnpainted,
1118    /// `font-invalid`: a font dictionary has a missing or malformed entry, so its text was decoded with defaults.
1119    FontInvalid,
1120    /// `cmap-invalid`: a font's CMap or ToUnicode CMap is malformed or names a predefined CMap Lamina PDF has no table for.
1121    CmapInvalid,
1122    /// `unmapped-glyph`: a font shows glyphs that nothing maps to text.
1123    UnmappedGlyph,
1124    /// `extract-limit-blocks`: a page had more runs of text than the extraction block limit; the runs past it were left out.
1125    ExtractLimitBlocks,
1126    /// `extract-reading-order-ambiguous`: a page mixes horizontal and vertical writing, so the order of its blocks is a guess.
1127    ExtractReadingOrderAmbiguous,
1128    /// `extract-table-ambiguous`: a table's rules marked out merged cells that aren't rectangles, so its cells were kept unmerged.
1129    ExtractTableAmbiguous,
1130    /// `extract-table-limit`: a page's ruling lines would make a table bigger than the extraction's cell limit; those lines gave no table.
1131    ExtractTableLimit,
1132    /// `extract-struct-tree-ignored`: a tagged page's structure tree covered too little of its text, or its order jumped back across columns too often, so the layout gave the reading order.
1133    ExtractStructTreeIgnored,
1134    /// `extract-untagged-content`: a page read in structure-tree order has visible text that is neither in the tree nor an artifact; it follows the tree's blocks, in layout order.
1135    ExtractUntaggedContent,
1136    /// `extract-needs-ocr`: a page has no usable text layer: it is an image (with or without an invisible OCR layer), outlined glyphs, or glyphs without Unicode, so its extracted text is empty or unreliable.
1137    ExtractNeedsOcr,
1138    /// `extract-column-order-uncertain`: the layout rules had to guess how a page's columns are read, so its blocks may be in the wrong order; the blocks concerned have a lower confidence.
1139    ExtractColumnOrderUncertain,
1140    /// `pdfa-one-author`: the file claims PDF/A-1, which allows one author, and its metadata lists more.
1141    PdfaOneAuthor,
1142    /// `pdfua-title-missing`: the file claims PDF/UA-1, which requires a title in its metadata, and it has none.
1143    PdfuaTitleMissing,
1144    /// `pdfa-info-mismatch`: the file claims PDF/A, which requires the Info dictionary and the XMP packet to agree, and they differ.
1145    PdfaInfoMismatch,
1146    /// `duplicate-tags-incomplete`: a duplicated page's content is partly untagged, which breaks the PDF/UA claim of the document's metadata.
1147    DuplicateTagsIncomplete,
1148    /// `imported-tags-dropped`: pages copied in from another document came without their tags, which breaks the PDF/UA claim of the document's metadata.
1149    ImportedTagsDropped,
1150    /// `imported-pdfa-unchecked`: pages copied in from a document that doesn't claim the same PDF/A level may break the PDF/A claim of the document's metadata.
1151    ImportedPdfaUnchecked,
1152    /// `imported-pdfua-unchecked`: pages copied in from a document that doesn't claim PDF/UA-1 may break the PDF/UA claim of the document's metadata.
1153    ImportedPdfuaUnchecked,
1154    /// `annot-without-contents`: a new or changed annotation has no description, which breaks the document's PDF/UA claim.
1155    AnnotWithoutContents,
1156    /// `annot-not-tagged`: a new annotation isn't in the structure tree, which breaks the document's PDF/UA claim.
1157    AnnotNotTagged,
1158    /// `pdfa-annot-flags`: an annotation doesn't print or is hidden, which breaks the document's PDF/A claim.
1159    PdfaAnnotFlags,
1160    /// `pdfa-transparency`: an annotation is translucent or blends, which PDF/A-1 forbids.
1161    PdfaTransparency,
1162    /// `tounicode-conflict`: one glyph was used for two different texts; ToUnicode keeps the first.
1163    TounicodeConflict,
1164    /// `whole-font-rebuilt`: a font that forbids subsetting was rebuilt with every glyph kept.
1165    WholeFontRebuilt,
1166    /// `flow-keep-broken`: blocks kept together are taller than a page, so the flow split them.
1167    FlowKeepBroken,
1168    /// `markdown-html-ignored`: the Markdown holds raw HTML, which the PDF leaves out.
1169    MarkdownHtmlIgnored,
1170    /// `markdown-image-missing`: the Markdown names an image that wasn't supplied, so the PDF leaves it out.
1171    MarkdownImageMissing,
1172    /// `covered-text`: a page draws text and then paints a shape, an image or an annotation over it, so the text is hidden but still in the file.
1173    CoveredText,
1174    /// `redaction-not-applied`: a page has redaction marks that were never applied, so the text under them is still in the file.
1175    RedactionNotApplied,
1176    /// `text-in-earlier-revision`: an earlier revision of the file holds text that the latest revision no longer has.
1177    TextInEarlierRevision,
1178}
1179
1180impl WarningCode {
1181    /// Every variant, in `codes.json` order.
1182    ///
1183    /// Added in 0.2.0.
1184    pub const ALL: &'static [Self] = &[
1185        Self::MissingHeader,
1186        Self::XrefRepaired,
1187        Self::XrefstmIgnored,
1188        Self::StreamLengthRecovered,
1189        Self::DictionaryKeySkipped,
1190        Self::StaleGeneration,
1191        Self::PageTreeNodeSkipped,
1192        Self::PageCountMismatch,
1193        Self::FlateTruncated,
1194        Self::FilterCharactersSkipped,
1195        Self::ObjstmIndexMismatch,
1196        Self::ObjectNumberOutOfRange,
1197        Self::AesPaddingInvalid,
1198        Self::PermsMismatch,
1199        Self::WarningsTruncated,
1200        Self::InvalidBox,
1201        Self::InvalidRotate,
1202        Self::NameTreeNodeSkipped,
1203        Self::OutlineCycle,
1204        Self::OutlineItemSkipped,
1205        Self::InvalidDate,
1206        Self::XmpInvalid,
1207        Self::AnnotNameDuplicate,
1208        Self::XmpRepaired,
1209        Self::InvalidPageLabel,
1210        Self::InvalidEntry,
1211        Self::ContentUnknownOperator,
1212        Self::ContentBadOperands,
1213        Self::ContentUnbalancedQ,
1214        Self::ContentUnbalancedBt,
1215        Self::ContentUnbalancedMarked,
1216        Self::ContentSyntax,
1217        Self::ContentResourceMissing,
1218        Self::InlineImageUnterminated,
1219        Self::XobjectCycle,
1220        Self::ContentPathUnpainted,
1221        Self::FontInvalid,
1222        Self::CmapInvalid,
1223        Self::UnmappedGlyph,
1224        Self::ExtractLimitBlocks,
1225        Self::ExtractReadingOrderAmbiguous,
1226        Self::ExtractTableAmbiguous,
1227        Self::ExtractTableLimit,
1228        Self::ExtractStructTreeIgnored,
1229        Self::ExtractUntaggedContent,
1230        Self::ExtractNeedsOcr,
1231        Self::ExtractColumnOrderUncertain,
1232        Self::PdfaOneAuthor,
1233        Self::PdfuaTitleMissing,
1234        Self::PdfaInfoMismatch,
1235        Self::DuplicateTagsIncomplete,
1236        Self::ImportedTagsDropped,
1237        Self::ImportedPdfaUnchecked,
1238        Self::ImportedPdfuaUnchecked,
1239        Self::AnnotWithoutContents,
1240        Self::AnnotNotTagged,
1241        Self::PdfaAnnotFlags,
1242        Self::PdfaTransparency,
1243        Self::TounicodeConflict,
1244        Self::WholeFontRebuilt,
1245        Self::FlowKeepBroken,
1246        Self::MarkdownHtmlIgnored,
1247        Self::MarkdownImageMissing,
1248        Self::CoveredText,
1249        Self::RedactionNotApplied,
1250        Self::TextInEarlierRevision,
1251    ];
1252
1253    /// The code with this name, if there is one.
1254    ///
1255    /// Added in 0.2.0.
1256    #[must_use]
1257    pub const fn from_code(code: &str) -> Option<Self> {
1258        let mut rest = Self::ALL;
1259        while let [first, tail @ ..] = rest {
1260            if bytes_eq(first.as_str().as_bytes(), code.as_bytes()) {
1261                return Some(*first);
1262            }
1263            rest = tail;
1264        }
1265        None
1266    }
1267
1268    /// The kebab-case code.
1269    ///
1270    /// Added in 0.2.0.
1271    #[must_use]
1272    pub const fn as_str(self) -> &'static str {
1273        match self {
1274            Self::MissingHeader => "missing-header",
1275            Self::XrefRepaired => "xref-repaired",
1276            Self::XrefstmIgnored => "xrefstm-ignored",
1277            Self::StreamLengthRecovered => "stream-length-recovered",
1278            Self::DictionaryKeySkipped => "dictionary-key-skipped",
1279            Self::StaleGeneration => "stale-generation",
1280            Self::PageTreeNodeSkipped => "page-tree-node-skipped",
1281            Self::PageCountMismatch => "page-count-mismatch",
1282            Self::FlateTruncated => "flate-truncated",
1283            Self::FilterCharactersSkipped => "filter-characters-skipped",
1284            Self::ObjstmIndexMismatch => "objstm-index-mismatch",
1285            Self::ObjectNumberOutOfRange => "object-number-out-of-range",
1286            Self::AesPaddingInvalid => "aes-padding-invalid",
1287            Self::PermsMismatch => "perms-mismatch",
1288            Self::WarningsTruncated => "warnings-truncated",
1289            Self::InvalidBox => "invalid-box",
1290            Self::InvalidRotate => "invalid-rotate",
1291            Self::NameTreeNodeSkipped => "name-tree-node-skipped",
1292            Self::OutlineCycle => "outline-cycle",
1293            Self::OutlineItemSkipped => "outline-item-skipped",
1294            Self::InvalidDate => "invalid-date",
1295            Self::XmpInvalid => "xmp-invalid",
1296            Self::AnnotNameDuplicate => "annot-name-duplicate",
1297            Self::XmpRepaired => "xmp-repaired",
1298            Self::InvalidPageLabel => "invalid-page-label",
1299            Self::InvalidEntry => "invalid-entry",
1300            Self::ContentUnknownOperator => "content-unknown-operator",
1301            Self::ContentBadOperands => "content-bad-operands",
1302            Self::ContentUnbalancedQ => "content-unbalanced-q",
1303            Self::ContentUnbalancedBt => "content-unbalanced-bt",
1304            Self::ContentUnbalancedMarked => "content-unbalanced-marked",
1305            Self::ContentSyntax => "content-syntax",
1306            Self::ContentResourceMissing => "content-resource-missing",
1307            Self::InlineImageUnterminated => "inline-image-unterminated",
1308            Self::XobjectCycle => "xobject-cycle",
1309            Self::ContentPathUnpainted => "content-path-unpainted",
1310            Self::FontInvalid => "font-invalid",
1311            Self::CmapInvalid => "cmap-invalid",
1312            Self::UnmappedGlyph => "unmapped-glyph",
1313            Self::ExtractLimitBlocks => "extract-limit-blocks",
1314            Self::ExtractReadingOrderAmbiguous => "extract-reading-order-ambiguous",
1315            Self::ExtractTableAmbiguous => "extract-table-ambiguous",
1316            Self::ExtractTableLimit => "extract-table-limit",
1317            Self::ExtractStructTreeIgnored => "extract-struct-tree-ignored",
1318            Self::ExtractUntaggedContent => "extract-untagged-content",
1319            Self::ExtractNeedsOcr => "extract-needs-ocr",
1320            Self::ExtractColumnOrderUncertain => "extract-column-order-uncertain",
1321            Self::PdfaOneAuthor => "pdfa-one-author",
1322            Self::PdfuaTitleMissing => "pdfua-title-missing",
1323            Self::PdfaInfoMismatch => "pdfa-info-mismatch",
1324            Self::DuplicateTagsIncomplete => "duplicate-tags-incomplete",
1325            Self::ImportedTagsDropped => "imported-tags-dropped",
1326            Self::ImportedPdfaUnchecked => "imported-pdfa-unchecked",
1327            Self::ImportedPdfuaUnchecked => "imported-pdfua-unchecked",
1328            Self::AnnotWithoutContents => "annot-without-contents",
1329            Self::AnnotNotTagged => "annot-not-tagged",
1330            Self::PdfaAnnotFlags => "pdfa-annot-flags",
1331            Self::PdfaTransparency => "pdfa-transparency",
1332            Self::TounicodeConflict => "tounicode-conflict",
1333            Self::WholeFontRebuilt => "whole-font-rebuilt",
1334            Self::FlowKeepBroken => "flow-keep-broken",
1335            Self::MarkdownHtmlIgnored => "markdown-html-ignored",
1336            Self::MarkdownImageMissing => "markdown-image-missing",
1337            Self::CoveredText => "covered-text",
1338            Self::RedactionNotApplied => "redaction-not-applied",
1339            Self::TextInEarlierRevision => "text-in-earlier-revision",
1340        }
1341    }
1342
1343    /// The kind (ADR 0026 §2).
1344    ///
1345    /// Added in 0.2.0.
1346    #[must_use]
1347    pub const fn kind(self) -> ErrorKind {
1348        match self {
1349            Self::MissingHeader => ErrorKind::Input,
1350            Self::XrefRepaired => ErrorKind::Input,
1351            Self::XrefstmIgnored => ErrorKind::Input,
1352            Self::StreamLengthRecovered => ErrorKind::Input,
1353            Self::DictionaryKeySkipped => ErrorKind::Input,
1354            Self::StaleGeneration => ErrorKind::Input,
1355            Self::PageTreeNodeSkipped => ErrorKind::Input,
1356            Self::PageCountMismatch => ErrorKind::Input,
1357            Self::FlateTruncated => ErrorKind::Input,
1358            Self::FilterCharactersSkipped => ErrorKind::Input,
1359            Self::ObjstmIndexMismatch => ErrorKind::Input,
1360            Self::ObjectNumberOutOfRange => ErrorKind::Limit,
1361            Self::AesPaddingInvalid => ErrorKind::Security,
1362            Self::PermsMismatch => ErrorKind::Security,
1363            Self::WarningsTruncated => ErrorKind::Limit,
1364            Self::InvalidBox => ErrorKind::Input,
1365            Self::InvalidRotate => ErrorKind::Input,
1366            Self::NameTreeNodeSkipped => ErrorKind::Input,
1367            Self::OutlineCycle => ErrorKind::Input,
1368            Self::OutlineItemSkipped => ErrorKind::Input,
1369            Self::InvalidDate => ErrorKind::Input,
1370            Self::XmpInvalid => ErrorKind::Input,
1371            Self::AnnotNameDuplicate => ErrorKind::Input,
1372            Self::XmpRepaired => ErrorKind::Input,
1373            Self::InvalidPageLabel => ErrorKind::Input,
1374            Self::InvalidEntry => ErrorKind::Input,
1375            Self::ContentUnknownOperator => ErrorKind::Input,
1376            Self::ContentBadOperands => ErrorKind::Input,
1377            Self::ContentUnbalancedQ => ErrorKind::Input,
1378            Self::ContentUnbalancedBt => ErrorKind::Input,
1379            Self::ContentUnbalancedMarked => ErrorKind::Input,
1380            Self::ContentSyntax => ErrorKind::Input,
1381            Self::ContentResourceMissing => ErrorKind::Input,
1382            Self::InlineImageUnterminated => ErrorKind::Input,
1383            Self::XobjectCycle => ErrorKind::Input,
1384            Self::ContentPathUnpainted => ErrorKind::Input,
1385            Self::FontInvalid => ErrorKind::Input,
1386            Self::CmapInvalid => ErrorKind::Input,
1387            Self::UnmappedGlyph => ErrorKind::Input,
1388            Self::ExtractLimitBlocks => ErrorKind::Limit,
1389            Self::ExtractReadingOrderAmbiguous => ErrorKind::Unsupported,
1390            Self::ExtractTableAmbiguous => ErrorKind::Unsupported,
1391            Self::ExtractTableLimit => ErrorKind::Limit,
1392            Self::ExtractStructTreeIgnored => ErrorKind::Input,
1393            Self::ExtractUntaggedContent => ErrorKind::Input,
1394            Self::ExtractNeedsOcr => ErrorKind::Unsupported,
1395            Self::ExtractColumnOrderUncertain => ErrorKind::Unsupported,
1396            Self::PdfaOneAuthor => ErrorKind::Usage,
1397            Self::PdfuaTitleMissing => ErrorKind::Usage,
1398            Self::PdfaInfoMismatch => ErrorKind::Input,
1399            Self::DuplicateTagsIncomplete => ErrorKind::Usage,
1400            Self::ImportedTagsDropped => ErrorKind::Usage,
1401            Self::ImportedPdfaUnchecked => ErrorKind::Usage,
1402            Self::ImportedPdfuaUnchecked => ErrorKind::Usage,
1403            Self::AnnotWithoutContents => ErrorKind::Usage,
1404            Self::AnnotNotTagged => ErrorKind::Usage,
1405            Self::PdfaAnnotFlags => ErrorKind::Usage,
1406            Self::PdfaTransparency => ErrorKind::Usage,
1407            Self::TounicodeConflict => ErrorKind::Usage,
1408            Self::WholeFontRebuilt => ErrorKind::Usage,
1409            Self::FlowKeepBroken => ErrorKind::Usage,
1410            Self::MarkdownHtmlIgnored => ErrorKind::Unsupported,
1411            Self::MarkdownImageMissing => ErrorKind::Usage,
1412            Self::CoveredText => ErrorKind::Security,
1413            Self::RedactionNotApplied => ErrorKind::Security,
1414            Self::TextInEarlierRevision => ErrorKind::Security,
1415        }
1416    }
1417
1418    /// One lowercase sentence: what happened.
1419    ///
1420    /// Added in 0.2.0.
1421    #[must_use]
1422    pub const fn summary(self) -> &'static str {
1423        match self {
1424            Self::MissingHeader => "no %PDF-x.y header in the first 1,024 bytes; parsing went ahead",
1425            Self::XrefRepaired => "the stored cross-reference data was unusable and was rebuilt by scanning",
1426            Self::XrefstmIgnored => "a hybrid file's /XRefStm could not be read and was ignored",
1427            Self::StreamLengthRecovered => "a stream's /Length was wrong, so its end was found by scanning for endstream",
1428            Self::DictionaryKeySkipped => "a dictionary had something other than a name where a key belongs, and it was skipped",
1429            Self::StaleGeneration => "a reference's generation did not match its xref entry, so it resolved to null",
1430            Self::PageTreeNodeSkipped => "a page-tree node was missing, malformed or too deep, and was skipped",
1431            Self::PageCountMismatch => "the page tree's /Count differs from the number of pages walked",
1432            Self::FlateTruncated => "Flate data was truncated or had a bad checksum; the partial output was kept",
1433            Self::FilterCharactersSkipped => "ASCIIHex or ASCII85 data held characters outside the filter's alphabet; they were skipped",
1434            Self::ObjstmIndexMismatch => "an object stream's index was stale and the object was found by searching",
1435            Self::ObjectNumberOutOfRange => "an xref entry above max_object_number was dropped",
1436            Self::AesPaddingInvalid => "AES-encrypted data had a bad length or padding and was kept as stored",
1437            Self::PermsMismatch => "an R5/R6 document's /Perms does not match its /P and /EncryptMetadata",
1438            Self::WarningsTruncated => "more than max_warnings warnings were raised and the rest were dropped",
1439            Self::InvalidBox => "a page boundary box is not four numbers and reads as absent",
1440            Self::InvalidRotate => "a page's /Rotate is not a multiple of 90 and reads as 0",
1441            Self::NameTreeNodeSkipped => "a name- or number-tree node was malformed, repeated or too deep, and was skipped",
1442            Self::OutlineCycle => "an outline item was reached twice; that branch of the walk stopped",
1443            Self::OutlineItemSkipped => "an outline item was missing, not a dictionary or too deep, and was skipped with its subtree",
1444            Self::InvalidDate => "an Info date is not a valid PDF date; the raw string is kept",
1445            Self::XmpInvalid => "the XMP metadata packet is not readable XMP and reads as absent",
1446            Self::AnnotNameDuplicate => "two annotations on one page have the same name (/NM), which should be unique on its page",
1447            Self::XmpRepaired => "the XMP metadata packet had damage other readers read past, and was read the same way",
1448            Self::InvalidPageLabel => "a /PageLabels entry is malformed; the malformed part is dropped",
1449            Self::InvalidEntry => "an entry a view reads is unreadable or of the wrong type and reads as absent",
1450            Self::ContentUnknownOperator => "an operator the spec does not define was skipped outside a BX/EX section",
1451            Self::ContentBadOperands => "an operator had too few operands or operands of the wrong type, or extra ones",
1452            Self::ContentUnbalancedQ => "a Q without a matching q was ignored, or saved graphics states were left open",
1453            Self::ContentUnbalancedBt => "a text object was opened twice, closed outside one, or left open",
1454            Self::ContentUnbalancedMarked => "an EMC without a matching BMC or BDC was ignored, or marked content was left open",
1455            Self::ContentSyntax => "content-stream bytes that are not a token were skipped",
1456            Self::ContentResourceMissing => "an operator named a resource that is missing, of the wrong type or unreadable",
1457            Self::InlineImageUnterminated => "no EI ends an inline image; the rest of the content was skipped",
1458            Self::XobjectCycle => "a Form XObject draws itself, directly or through other forms",
1459            Self::ContentPathUnpainted => "a content stream ended with a path no painting operator ended",
1460            Self::FontInvalid => "a font dictionary has a missing or malformed entry, so its text was decoded with defaults",
1461            Self::CmapInvalid => "a font's CMap or ToUnicode CMap is malformed or names a predefined CMap Lamina PDF has no table for",
1462            Self::UnmappedGlyph => "a font shows glyphs that nothing maps to text",
1463            Self::ExtractLimitBlocks => "a page had more runs of text than the extraction block limit; the runs past it were left out",
1464            Self::ExtractReadingOrderAmbiguous => "a page mixes horizontal and vertical writing, so the order of its blocks is a guess",
1465            Self::ExtractTableAmbiguous => "a table's rules marked out merged cells that aren't rectangles, so its cells were kept unmerged",
1466            Self::ExtractTableLimit => "a page's ruling lines would make a table bigger than the extraction's cell limit; those lines gave no table",
1467            Self::ExtractStructTreeIgnored => "a tagged page's structure tree covered too little of its text, or its order jumped back across columns too often, so the layout gave the reading order",
1468            Self::ExtractUntaggedContent => "a page read in structure-tree order has visible text that is neither in the tree nor an artifact; it follows the tree's blocks, in layout order",
1469            Self::ExtractNeedsOcr => "a page has no usable text layer: it is an image (with or without an invisible OCR layer), outlined glyphs, or glyphs without Unicode, so its extracted text is empty or unreliable",
1470            Self::ExtractColumnOrderUncertain => "the layout rules had to guess how a page's columns are read, so its blocks may be in the wrong order; the blocks concerned have a lower confidence",
1471            Self::PdfaOneAuthor => "the file claims PDF/A-1, which allows one author, and its metadata lists more",
1472            Self::PdfuaTitleMissing => "the file claims PDF/UA-1, which requires a title in its metadata, and it has none",
1473            Self::PdfaInfoMismatch => "the file claims PDF/A, which requires the Info dictionary and the XMP packet to agree, and they differ",
1474            Self::DuplicateTagsIncomplete => "a duplicated page's content is partly untagged, which breaks the PDF/UA claim of the document's metadata",
1475            Self::ImportedTagsDropped => "pages copied in from another document came without their tags, which breaks the PDF/UA claim of the document's metadata",
1476            Self::ImportedPdfaUnchecked => "pages copied in from a document that doesn't claim the same PDF/A level may break the PDF/A claim of the document's metadata",
1477            Self::ImportedPdfuaUnchecked => "pages copied in from a document that doesn't claim PDF/UA-1 may break the PDF/UA claim of the document's metadata",
1478            Self::AnnotWithoutContents => "a new or changed annotation has no description, which breaks the document's PDF/UA claim",
1479            Self::AnnotNotTagged => "a new annotation isn't in the structure tree, which breaks the document's PDF/UA claim",
1480            Self::PdfaAnnotFlags => "an annotation doesn't print or is hidden, which breaks the document's PDF/A claim",
1481            Self::PdfaTransparency => "an annotation is translucent or blends, which PDF/A-1 forbids",
1482            Self::TounicodeConflict => "one glyph was used for two different texts; ToUnicode keeps the first",
1483            Self::WholeFontRebuilt => "a font that forbids subsetting was rebuilt with every glyph kept",
1484            Self::FlowKeepBroken => "blocks kept together are taller than a page, so the flow split them",
1485            Self::MarkdownHtmlIgnored => "the Markdown holds raw HTML, which the PDF leaves out",
1486            Self::MarkdownImageMissing => "the Markdown names an image that wasn't supplied, so the PDF leaves it out",
1487            Self::CoveredText => "a page draws text and then paints a shape, an image or an annotation over it, so the text is hidden but still in the file",
1488            Self::RedactionNotApplied => "a page has redaction marks that were never applied, so the text under them is still in the file",
1489            Self::TextInEarlierRevision => "an earlier revision of the file holds text that the latest revision no longer has",
1490        }
1491    }
1492
1493    /// The hint (ADR 0026 §5), with its `{limit}`/`{option}` parameters unfilled.
1494    ///
1495    /// Added in 0.2.0.
1496    #[must_use]
1497    pub const fn hint(self) -> &'static str {
1498        match self {
1499            Self::MissingHeader => "nothing to do if the document reads correctly; open in strict mode to refuse such files",
1500            Self::XrefRepaired => "check the result; save with a full rewrite, since an incremental update refuses a repaired base",
1501            Self::XrefstmIgnored => "nothing to do; the classic xref table is used instead",
1502            Self::StreamLengthRecovered => "nothing to do; a full rewrite writes the correct length",
1503            Self::DictionaryKeySkipped => "nothing to do if the document reads correctly; open in strict mode to refuse such files",
1504            Self::StaleGeneration => "nothing to do; the reference is treated as missing",
1505            Self::PageTreeNodeSkipped => "check the page count: pages under the skipped node are missing",
1506            Self::PageCountMismatch => "nothing to do; Lamina PDF uses the walked page count",
1507            Self::FlateTruncated => "check the affected content: the end of the stream may be missing",
1508            Self::FilterCharactersSkipped => "check the affected content: the stream is damaged, and what decoded may differ from what was written",
1509            Self::ObjstmIndexMismatch => "nothing to do; a full rewrite writes a correct index",
1510            Self::ObjectNumberOutOfRange => "raise max_object_number in Limits only if you trust the input",
1511            Self::AesPaddingInvalid => "treat the affected strings and streams as suspect: they may have been tampered with",
1512            Self::PermsMismatch => "treat the document's permissions as untrusted",
1513            Self::WarningsTruncated => "raise max_warnings in Limits if you need the full list",
1514            Self::InvalidBox => "nothing to do; the page uses the next box in the fallback chain",
1515            Self::InvalidRotate => "set the page rotation explicitly if 0 is wrong",
1516            Self::NameTreeNodeSkipped => "check the tree's entries: those under the skipped node are missing",
1517            Self::OutlineCycle => "nothing to do; the outline is read without the loop",
1518            Self::OutlineItemSkipped => "check the outline: the skipped item and its children are missing",
1519            Self::InvalidDate => "read the raw value from the Info view if you need it",
1520            Self::XmpInvalid => "nothing to do; a metadata edit asks before replacing it",
1521            Self::AnnotNameDuplicate => "nothing to do; both are kept, and annotations are told apart by their own IDs",
1522            Self::XmpRepaired => "nothing to do; a metadata edit writes the declarations the packet left out",
1523            Self::InvalidPageLabel => "nothing to do; affected pages fall back to decimal labels",
1524            Self::InvalidEntry => "nothing to do; the view uses the entry's default",
1525            Self::ContentUnknownOperator => "nothing to do; check the page's rendering if the operator mattered",
1526            Self::ContentBadOperands => "nothing to do; the operator was skipped or used its last operands",
1527            Self::ContentUnbalancedQ => "nothing to do; the graphics state was restored as the spec intends",
1528            Self::ContentUnbalancedBt => "nothing to do; text operators outside a text object were handled tolerantly",
1529            Self::ContentUnbalancedMarked => "check tagged-content results: marked-content sequences were closed for you",
1530            Self::ContentSyntax => "check the page's content: the bytes around the reported offset were skipped",
1531            Self::ContentResourceMissing => "check the page's resources: the operator ran without the resource or was skipped",
1532            Self::InlineImageUnterminated => "check the page's content: everything after the inline image is missing",
1533            Self::XobjectCycle => "nothing to do; the inner Do was skipped",
1534            Self::ContentPathUnpainted => "nothing to do; the unpainted path was dropped as the spec intends",
1535            Self::FontInvalid => "nothing to do; extracted text or positions for that font may be off",
1536            Self::CmapInvalid => "nothing to do; the bad entries were skipped and the rest of the CMap is used",
1537            Self::UnmappedGlyph => "nothing to do; those glyphs extract as U+FFFD (the file needs a ToUnicode CMap)",
1538            Self::ExtractLimitBlocks => "raise ExtractLimits::max_blocks_per_page if the page really has that many blocks",
1539            Self::ExtractReadingOrderAmbiguous => "nothing to do; check the order of that page's blocks, or ask for content order",
1540            Self::ExtractTableAmbiguous => "nothing to do; check that table's cells, whose text may be split across neighbours",
1541            Self::ExtractTableLimit => "raise ExtractLimits::max_table_cells if the page really has a table that big",
1542            Self::ExtractStructTreeIgnored => "nothing to do; ReadingOrder::Tagged uses the tree anyway",
1543            Self::ExtractUntaggedContent => "nothing to do; tag that text in the file to give it a place in the reading order",
1544            Self::ExtractNeedsOcr => "run OCR or a vision model on this page; the page's textLayer in the JSON says which case it is",
1545            Self::ExtractColumnOrderUncertain => "check the page, or send it to a layout model; the warning's reason says which guess was made",
1546            Self::PdfaOneAuthor => "keep one author (join the names into one), or save knowing the file no longer meets PDF/A-1",
1547            Self::PdfuaTitleMissing => "give the document a title before saving, or save knowing the file no longer meets PDF/UA-1",
1548            Self::PdfaInfoMismatch => "edit the metadata with setMetadata, which writes both, or remove the Info entries that differ",
1549            Self::DuplicateTagsIncomplete => "retag the copy, or duplicate pages whose tagged elements lie on the page alone",
1550            Self::ImportedTagsDropped => "tag the copied pages in a tagging tool, or copy pages from a document without tags",
1551            Self::ImportedPdfaUnchecked => "check the saved file with a PDF/A validator such as veraPDF, or copy pages from a document that claims the same level",
1552            Self::ImportedPdfuaUnchecked => "check the saved file's tags, alternate text and reading order with a PDF/UA checker such as veraPDF, or copy pages from a document that claims PDF/UA-1",
1553            Self::AnnotWithoutContents => "give the annotation a description: the text it marks, or what the mark means",
1554            Self::AnnotNotTagged => "tag the document first, or add the annotation to a copy that doesn't claim PDF/UA",
1555            Self::PdfaAnnotFlags => "keep the annotation's Print flag and clear Hidden, Invisible, NoView and ToggleNoView",
1556            Self::PdfaTransparency => "make the mark opaque, or use an underline instead of a highlight",
1557            Self::TounicodeConflict => "mark the second occurrence with /ActualText so extraction gets its text",
1558            Self::WholeFontRebuilt => "check that the font's licence allows this, or use a static TrueType or CFF version",
1559            Self::FlowKeepBroken => "split the keep group or drop keep-with-next on a heading chain, or use a taller page",
1560            Self::MarkdownHtmlIgnored => "write the content in Markdown instead of HTML, or remove the HTML",
1561            Self::MarkdownImageMissing => "pass the image's bytes with MarkdownBuildOptions::with_image under the path the Markdown uses",
1562            Self::CoveredText => "remove the text itself with a tool that deletes what a redaction covers, then save a full rewrite",
1563            Self::RedactionNotApplied => "apply the redactions in a tool that removes what they cover, then save a full rewrite",
1564            Self::TextInEarlierRevision => "save the file as a full rewrite, which keeps only the latest revision",
1565        }
1566    }
1567
1568    /// The code's explain page (`docsUrl`, ADR 0026 §6).
1569    ///
1570    /// Added in 0.2.0.
1571    #[must_use]
1572    pub fn docs_url(self) -> String {
1573        format!("{DOCS_URL_BASE}{}{DOCS_URL_SUFFIX}", self.as_str())
1574    }
1575}