Skip to content

Commit

Permalink
fix #425: discard lines with invalid characters in log files to avoid…
Browse files Browse the repository at this point in the history
… spurious warnings
  • Loading branch information
yihui committed Oct 12, 2023
1 parent f8dc154 commit 95c90c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tinytex
Type: Package
Title: Helper Functions to Install and Maintain TeX Live, and Compile LaTeX Documents
Version: 0.47.2
Version: 0.47.3
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre", "cph"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person(given = "Posit Software, PBC", role = c("cph", "fnd")),
Expand Down
4 changes: 2 additions & 2 deletions R/latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ tweak_aux = function(aux, x = read_lines(aux)) {
writeLines(x, aux)
}

needs_rerun = function(log, text = xfun::read_utf8(log)) {
needs_rerun = function(log, text = read_lines(log)) {
any(grepl(
'(Rerun to get |Please \\(?re\\)?run | Rerun LaTeX\\.)', text,
useBytes = TRUE
Expand All @@ -314,7 +314,7 @@ system2_quiet = function(..., error = NULL, logfile = NULL, fail_rerun = TRUE) {

# run the command quietly if possible
res = system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2)
if (is.character(logfile) && file.exists(f2) && length(e <- xfun::read_utf8(f2))) {
if (is.character(logfile) && file.exists(f2) && length(e <- read_lines(f2))) {
i = grep('^\\s*$', e, invert = TRUE)
e[i] = paste('!', e[i]) # prepend ! to non-empty error messages
cat('', e, file = logfile, sep = '\n', append = TRUE)
Expand Down
9 changes: 8 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ xfun_session_info = function() {
paste(c('LaTeX version used: ', paste0(' ', info)), collapse = '\n')
}

read_lines = function(...) readLines(..., warn = FALSE)
# read a file without warning, and discard lines with invalid characters to
# avoid warnings in the grep() family (invalid lines in log files should be safe
# to discard in this package, although it isn't so in general)
read_lines = function(...) {
x = readLines(..., warn = FALSE)
x[!validEnc(x)] = ''
x
}

0 comments on commit 95c90c8

Please sign in to comment.