Skip to content

Commit

Permalink
when the connection is no longer valid, mention the most likely reaso…
Browse files Browse the repository at this point in the history
…n: closeAllConnections() might have been called

quarto-dev/quarto-cli#5214
  • Loading branch information
yihui committed Apr 17, 2023
1 parent 17918f6 commit 25c3ceb
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: evaluate
Type: Package
Title: Parsing and Evaluation Tools that Provide More Details than the Default
Version: 0.20.1
Version: 0.20.2
Authors@R: c(
person("Hadley", "Wickham", role = "aut"),
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Version 0.21
these cause code and warnings (respectively) to be immediately emitted to
`stderr()`. This is useful for logging in unattended environments (#118).

- Improved the error message when users accidentally called `closeAllConnections()` (thanks, @guslipkin, quarto-dev/quarto-cli#5214).

Version 0.20
================================================================================

Expand Down
11 changes: 8 additions & 3 deletions R/watcher.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ watchout <- function(debug = FALSE) {
list(
get_new = function(plot = FALSE, incomplete_plots = FALSE,
text_callback = identity, graphics_callback = identity) {
incomplete <- isIncomplete(con)
incomplete <- test_con(con, isIncomplete)
if (incomplete) cat("\n")

out <- list()
Expand All @@ -42,8 +42,7 @@ watchout <- function(debug = FALSE) {
pause = function() sink(),
unpause = function() sink(con, split = debug),
close = function() {
if (!isOpen(con))
stop("something bad happened... did you use closeAllConnections()?")
test_con(con, isOpen)
sink()
close(con)
output
Expand All @@ -52,6 +51,12 @@ watchout <- function(debug = FALSE) {
)
}

test_con = function(con, test) {
tryCatch(test(con), error = function(e) stop(
e$message, '... Please make sure not to call closeAllConnections().'
))
}

.env = new.env()
.env$flush_console = function() {}

Expand Down

0 comments on commit 25c3ceb

Please sign in to comment.