XdrJsonError
public enum XdrJsonError : Error, Sendable
Errors raised while converting between XDR values and XDR-JSON.
Every case names the type being converted and, where one applies, the offending key, so a failure deep inside a transaction envelope can be located without re-running the conversion.
Payloads carry the offending text verbatim, so a caller can act on it. message is
where the four cases whose payload comes from the document – a duplicate key, an
unknown enumeration value, an unknown union arm and an undeclared field – neutralise it
through XdrJson/preview(_:), so an error echoed into a terminal or a log cannot carry
escape sequences of its own.
-
The text is not well-formed JSON.
Declaration
Swift
case malformedJson(message: String) -
A value has the wrong JSON type for the XDR field it maps to.
Declaration
Swift
case unexpectedType(type: String, key: String?, expected: String, got: String) -
A required key is absent. An optional XDR field may be
null, but its key must still be present.Declaration
Swift
case missingField(type: String, key: String) -
An object carries the same key twice, which has no canonical meaning.
Declaration
Swift
case duplicateKey(type: String, key: String) -
A string does not name any member of the enumeration it maps to.
Declaration
Swift
case unknownEnumValue(type: String, value: String) -
An object key does not name any arm of the union it maps to.
Declaration
Swift
case unknownUnionArm(type: String, key: String) -
An object carries keys the type does not declare.
The structural dual of
missingField(type:key:): one reports a declared key that is absent, this one a present key that is not declared.keysis a list because a single object can carry several, and both payloads are verbatim so a caller reading a document from a newer producer can act on them rather than parsing the message.Declaration
Swift
case unknownField(type: String, keys: [String], declared: [String]) -
A value has the right JSON type but is outside the domain the XDR type accepts.
Declaration
Swift
case invalidValue(type: String, key: String?, message: String) -
The document nests containers more deeply than the conversion allows.
Declaration
Swift
case recursionLimitExceeded(limit: Int) -
The XDR value is valid but has no XDR-JSON rendering the ecosystem accepts.
Declaration
Swift
case unrepresentable(type: String, message: String) -
A one-line description naming the type, the key and the reason.
Declaration
Swift
var message: String { get }
View on GitHub
Install in Dash