1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/// Non-fatal findings produced while interpreting an `.sdocx` archive.
#[derive(Debug, Clone, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ParseReport {
/// Findings in deterministic archive/page order.
pub diagnostics: Vec<ParseDiagnostic>,
}
impl ParseReport {
/// Whether the parser found anything callers should surface or inspect.
pub fn has_warnings(&self) -> bool {
!self.diagnostics.is_empty()
}
pub(crate) fn warning(
&mut self,
code: DiagnosticCode,
archive_entry: Option<String>,
message: impl Into<String>,
) {
self.diagnostics.push(ParseDiagnostic {
severity: DiagnosticSeverity::Warning,
code,
archive_entry,
message: message.into(),
});
}
}
/// One non-fatal parser finding.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ParseDiagnostic {
/// Finding severity.
pub severity: DiagnosticSeverity,
/// Stable machine-readable category.
pub code: DiagnosticCode,
/// Related ZIP entry, when the finding belongs to one entry.
pub archive_entry: Option<String>,
/// Human-readable detail.
pub message: String,
}
/// Severity of a parser diagnostic.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum DiagnosticSeverity {
/// Content was retained or skipped safely, but deserves inspection.
Warning,
}
/// Stable category for a parser diagnostic.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum DiagnosticCode {
IntegrityMismatch,
IntegrityUnavailable,
InvalidEndTag,
/// `pageIdInfo.dat` is absent, so filename order is used.
MissingPageManifest,
/// A manifest page identifier has no matching `.page` entry.
MissingPageEntry,
/// A `.page` entry is not listed in the page manifest.
UnlistedPageEntry,
/// The archive filename and embedded page UUID disagree.
PageIdentifierMismatch,
/// An object identifier is newer than the currently known SDK mapping.
UnknownObjectType,
UnsupportedObjectType,
UnsupportedContainerFeature,
UnresolvedObjectRenderLayer,
/// A text box contains optional fields or records without full semantic support.
UnsupportedTextBoxFeature,
/// Image data is retained but includes features not fully interpreted or rendered.
UnsupportedImageFeature,
/// Page template or background settings have no verified renderer.
UnsupportedPageTemplate,
/// The main image asset is absent, unsupported, or ambiguous.
UnresolvedImageMedia,
/// Without a media manifest, a unique numeric filename prefix was used.
InferredImageMediaReference,
/// Shape or line data is retained but not fully interpreted or rendered.
UnsupportedShapeFeature,
}