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
//! Error types for all fiscal operations.
use thiserror::Error;
/// The primary error type returned by all public functions in `fiscal-core`,
/// `fiscal-crypto`, and `fiscal-sefaz`.
///
/// All variants are `#[non_exhaustive]` so new error cases can be added in
/// future releases without breaking downstream `match` arms.
#[derive(Debug, Error, PartialEq, Eq)]
#[non_exhaustive]
pub enum FiscalError {
/// A tax data field contains an illegal value (e.g. malformed CNPJ, wrong
/// field length, invalid access-key format).
#[error("Invalid tax data: {0}")]
InvalidTaxData(String),
/// An ICMS CST code is not recognised by the current tax computation module.
#[error("Unsupported ICMS CST: {0}")]
UnsupportedIcmsCst(String),
/// An ICMS CSOSN code is not recognised by the current tax computation module.
#[error("Unsupported ICMS CSOSN: {0}")]
UnsupportedIcmsCsosn(String),
/// A required XML field is absent. The `field` member names the missing tag.
#[error("Required tax field \"{field}\" is missing")]
MissingRequiredField {
/// Name of the required XML tag or parameter that was absent.
field: String,
},
/// A GTIN barcode value is malformed or has an invalid check digit.
#[error("Invalid GTIN: {0}")]
InvalidGtin(String),
/// An error occurred while building or serialising an XML document.
#[error("XML generation failed: {0}")]
XmlGeneration(String),
/// An error occurred while parsing an XML document.
#[error("XML parsing failed: {0}")]
XmlParsing(String),
/// SEFAZ returned a rejection status code for a submitted document or event.
#[error("SEFAZ rejected: [{code}] {message}")]
SefazRejection {
/// SEFAZ status code (`cStat`), e.g. `"301"`.
code: String,
/// Human-readable rejection message (`xMotivo`).
message: String,
},
/// An error occurred while loading, parsing, or using a PKCS#12 certificate.
#[error("Certificate error: {0}")]
Certificate(String),
/// A two-letter state abbreviation (UF) or IBGE numeric code was not found
/// in the lookup table.
#[error("Invalid state code: {0}")]
InvalidStateCode(String),
/// An error occurred while activating, loading, or applying contingency mode.
#[error("Contingency error: {0}")]
Contingency(String),
/// A TXT document is structurally invalid or references an unsupported layout.
#[error("Invalid TXT: {0}")]
InvalidTxt(String),
/// The supplied document is not of the expected type (e.g. not a valid
/// NFe TXT header).
#[error("Wrong document: {0}")]
WrongDocument(String),
/// An HTTP or network-level error occurred during SEFAZ communication.
#[error("Network error: {0}")]
Network(String),
/// A configuration JSON is invalid or missing required fields.
#[error("Config validation error: {0}")]
ConfigValidation(String),
}