Every error zucbor raises carries a condition class, so it can be caught
by kind rather than by matching the message, which may change. Every
class below inherits from zucbor_error.
Details
zucbor_invalid_argumentAn argument was unusable: an input that is not a raw vector, a flag that is not
TRUEorFALSE, a limit that is not a positive whole number within its range, or a valuecbor_encode()cannot write as given, such as partial names or a string that is not valid UTF-8.zucbor_parse_errorThe input is not well-formed CBOR: it ends early, uses a reserved encoding, has a misplaced "break", or has bytes after the item.
zucbor_invalid_errorThe input is well-formed but not valid: a text string that is not UTF-8, a tag whose content has the wrong type, a typed array whose length is not a whole number of elements, or a multi-dimensional array whose shape does not match its elements.
zucbor_deterministic_errordeterministic = TRUEand the input is not in RFC 8949 core deterministic encoding.zucbor_duplicate_keyA map has the same key twice and
duplicate_keys = FALSE.zucbor_unrepresentableThe input is valid CBOR but holds a value R cannot: a text string containing U+0000 or longer than an R string, a tag number beyond 2^53, an integer beyond 2^53 with
big_integers = "error", or an array dimension beyond R's limit.zucbor_unsupported_typecbor_encode()was given an R value with no CBOR form, such as a function, an environment,POSIXltor a data frame.zucbor_handler_errorA function in
cbor_decode()'stag_handlersraised an error. The condition carriestag, the tag number, andparent, the error the handler raised.zucbor_io_errorcbor_read()orcbor_read_seq()could not open its file or URL, or read from its connection. The message includes R's own.zucbor_limit_errorA limit was reached. The subclasses
zucbor_depth_limit,zucbor_size_limit,zucbor_item_limitandzucbor_cell_limitname which one.
A condition raised while checking input carries offset, the 0-based
byte offset of the item at fault, or NA when the validator that found
the fault reports no position; and status, the name of the underlying
status, such as "CborErrorUnexpectedEOF". It is there for diagnostics:
branch on the class, not on it. A limit error also carries limit, the
argument's name, such as "max_depth", and limit_value. A
zucbor_invalid_argument condition carries arg, the argument at fault.
Examples
tryCatch(
cbor_validate(as.raw(c(0x82, 0x01)), error = TRUE),
zucbor_parse_error = function(e) e$offset
)
#> [1] 2