Thanks to visit codestin.com
Credit goes to github.com

Skip to content

read_char() chokes on input with an invalid encoding #152

@cpsievert

Description

@cpsievert

I came across this by running revdepcheck::cloud_report() on shiny and it seems @hadley was seeing the same thing in r-lib/revdepcheck#288 and attempted to fix in #133, but that was never merged. In my case, I was seeing:

Processing package results  42% (ipc)
Error in readChar(path, nchars = file.info(path)$size, ...) : 
  invalid UTF-8 input in readChar()

It turns out the error was coming from this call to rcmdcheck:::get_test_fail() which in turns calls rcmdcheck:::read_char()

I can reproduce the error locally by trying to read in {ipc}'s testthat.Rout.fail file the same way as rcmdcheck:::read_char():

path <- "ipc-testthat.Rout.fail"
readChar(path, nchars = file.info(path)$size)
#> Error in readChar(path, nchars = file.info(path)$size) : 
#>  invalid UTF-8 input in readChar()

With useBytes = TRUE, I can successfully read the file, but another downstream failure happens in rcmdcheck:::get_test_fail()'s call to nchar() (I'm guessing this is why @hadley said #133 (comment))

txt <- readChar(path, nchars = file.info(path)$size, useBytes = TRUE)
nchar(txt)
#> Error in nchar(txt) : invalid multibyte string, element 1

However, if I change the encoding to UTF-8, then it works:

Encoding(tx)
#> "unknown"
nchar(enc2utf8(txt))
#> [1] 12252

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions