Skip to contents

Every error zuutf raises inherits from zuutf_error, then error and condition, so a caller can catch all of them, or one kind, with tryCatch(). Test code should match on the class, never on the message.

Details

ClassFieldsRaised when
zuutf_invalid_argumentwrong type, unknown encoding name, a "bytes" string without useBytes
zuutf_encoding_errorindex, offset, encodinginput that is ill-formed in its encoding under invalid = "error", or a code point a Latin-1 target cannot represent
zuutf_nul_errorindex, offsetutf_decode() meets U+0000, which an R string cannot hold
zuutf_base64_erroroffsetBase64 input that base64_decode()'s mode rejects
zuutf_size_erroran output longer than a string (2^31 - 1 bytes) or a raw vector can hold
zuutf_internal_errora simdutf result zuutf did not expect, or a kernel forced through SIMDUTF_FORCE_IMPLEMENTATION that this processor cannot run

index is the 1-based element of the input, offset the 1-based position of the first error in the input's code units (bytes for UTF-8, Latin-1 and ASCII; 16-bit units for UTF-16; 32-bit units for UTF-32), counted after any byte-order mark, and encoding the name of the encoding.

Examples

tryCatch(
  utf_valid("abc", encoding = "EBCDIC"),
  zuutf_invalid_argument = function(e) class(e)
)
#> [1] "zuutf_invalid_argument" "zuutf_error"            "error"                 
#> [4] "condition"