From 1fe938f608986851cca8fced408a9ad5d07cd42c Mon Sep 17 00:00:00 2001 From: Maximilian Scholz Date: Tue, 8 Sep 2026 22:12:57 +0200 Subject: [PATCH 1/2] Forward error_call value in Pool$release --- NEWS.md | 2 ++ R/pool.R | 2 +- tests/testthat/test-pool.R | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 779030e..35f7ffd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # pool (development version) +* `Pool$release()` now forwards `error_call` correctly when reporting invalid objects. + # pool 1.0.5 * Added compatibility for dbplyr's upcoming dialect-based dispatch. diff --git a/R/pool.R b/R/pool.R index 5a0efbe..8cfe806 100644 --- a/R/pool.R +++ b/R/pool.R @@ -78,7 +78,7 @@ Pool <- R6::R6Class( ## (sets up task to destroy the object if the number of ## total objects exceeds the minimum) release = function(object, error_call = caller_env()) { - pool_metadata <- pool_metadata(object, error_call = error_call()) + pool_metadata <- pool_metadata(object, error_call = error_call) if (pool_metadata$state == "free") { abort( "This object was already returned to the pool.", diff --git a/tests/testthat/test-pool.R b/tests/testthat/test-pool.R index 5ecf4b3..d58a81b 100644 --- a/tests/testthat/test-pool.R +++ b/tests/testthat/test-pool.R @@ -37,6 +37,13 @@ test_that("can fetch and release", { checkCounts(pool, free = 1, taken = 0) }) +test_that("releasing a non-pooled object gives an informative error", { + pool <- poolCreate(function() 1) + defer(poolClose(pool)) + + expect_error(pool$release(1), "not an pooled object") +}) + test_that("max size is enforced", { pool <- poolCreate(MockPooledObj$new, maxSize = 2) defer(poolClose(pool)) From 41acb48acbe18174f69213bf17572387e3788d92 Mon Sep 17 00:00:00 2001 From: Maximilian Scholz Date: Wed, 16 Sep 2026 00:08:37 +0200 Subject: [PATCH 2/2] Snapshot release error via a helper to show the call --- tests/testthat/_snaps/pool.md | 8 ++++++++ tests/testthat/test-pool.R | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/pool.md b/tests/testthat/_snaps/pool.md index a23eda3..119a3e9 100644 --- a/tests/testthat/_snaps/pool.md +++ b/tests/testthat/_snaps/pool.md @@ -25,6 +25,14 @@ Error in `poolClose()`: ! The pool has been closed. +# releasing a non-pooled object gives an informative error + + Code + release(1) + Condition + Error in `release()`: + ! `object` is not an pooled object. + # max size is enforced Code diff --git a/tests/testthat/test-pool.R b/tests/testthat/test-pool.R index d58a81b..f9e0aff 100644 --- a/tests/testthat/test-pool.R +++ b/tests/testthat/test-pool.R @@ -41,7 +41,8 @@ test_that("releasing a non-pooled object gives an informative error", { pool <- poolCreate(function() 1) defer(poolClose(pool)) - expect_error(pool$release(1), "not an pooled object") + release <- function(object) pool$release(object) + expect_snapshot(release(1), error = TRUE) }) test_that("max size is enforced", {