Skip to content

Commit

Permalink
Merge pull request #139 from mrc-ide/mrc-5470
Browse files Browse the repository at this point in the history
Never fail when looking up windows username fails when fetching configuration
  • Loading branch information
weshinsley authored Jul 11, 2024
2 parents ef9d4c0 + 444d9f0 commit 0880f2e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
10 changes: 9 additions & 1 deletion R/configuration.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-configuration.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

0 comments on commit 0880f2e

Please sign in to comment.