diff --git a/DESCRIPTION b/DESCRIPTION index 529df083..2c4e66ab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hipercow Title: High Performance Computing -Version: 1.0.32 +Version: 1.0.33 Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"), email = "rich.fitzjohn@gmail.com"), person("Wes", "Hinsley", role = "aut"), diff --git a/R/configuration.R b/R/configuration.R index ae53190a..3a35aab3 100644 --- a/R/configuration.R +++ b/R/configuration.R @@ -83,7 +83,15 @@ configuration_drivers <- function(root) { ## because it's useful to report, and this is where we'd want it ## reported. We could add this into the configuration itself, but ## that causes some pain for the testing there. - ret$windows$username <- windows_username() + ret$windows$username <- tryCatch( + windows_username(), + error = function(e) { + cli::cli_warn( + c("Failed to read windows username", + i = "Try 'windows_username()' to reproduce separately"), + parent = e) + "(???)" + }) } ret } diff --git a/drivers/windows/DESCRIPTION b/drivers/windows/DESCRIPTION index a2ceee3c..20a3c50a 100644 --- a/drivers/windows/DESCRIPTION +++ b/drivers/windows/DESCRIPTION @@ -1,6 +1,6 @@ Package: hipercow.windows Title: DIDE HPC Support for Windows -Version: 1.0.32 +Version: 1.0.33 Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"), email = "rich.fitzjohn@gmail.com"), person("Wes", "Hinsley", role = "aut"), diff --git a/tests/testthat/test-configuration.R b/tests/testthat/test-configuration.R index afb7fe0a..f10a4249 100644 --- a/tests/testthat/test-configuration.R +++ b/tests/testthat/test-configuration.R @@ -136,3 +136,30 @@ test_that("can add windows username to configuration", { cmp$windows$username <- "alice" expect_equal(res, cmp) }) + + +test_that("don't error if windows username lookup fails", { + elsewhere_register() + path_here <- withr::local_tempdir() + path_there <- withr::local_tempdir() + init_quietly(path_here) + init_quietly(path_there) + root <- hipercow_root(path_here) + suppressMessages( + hipercow_configure("elsewhere", path = path_there, root = path_here)) + + mock_username <- mockery::mock(stop("error looking up windows username")) + mockery::stub(configuration_drivers, "windows_username", mock_username) + + root$config <- c(root$config, list(windows = list(a = 1, b = 2))) + warn <- expect_warning( + res <- configuration_drivers(root), + "Failed to read windows username") + mockery::expect_called(mock_username, 1) + cmp <- root$config + cmp$windows$username <- "(???)" + expect_equal(res, cmp) + + expect_equal(conditionMessage(warn$parent), + "error looking up windows username") +})