From 490b7c21dae68b0e2959dd591018f9116bed3376 Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Thu, 16 Nov 2023 18:57:24 -0600 Subject: [PATCH] GH-38752: [R] Wrap rosetta detection in tryCatch (#38754) ### Rationale for this change We should never allow rosetta checking from causing an error ### What changes are included in this PR? ~Wrap rosetta checking in a tryCatch~ our use of `try()` wasn't doing what we thought, it actually needs to have `silent = TRUE` specified to _not_ error. ### Are these changes tested? I tested them locally by manipulating the system call to a mangled command that doesn't exist, observing the error on load, then wrapping in trycatch. We might consider adding a test in CI, though there would be considerable complexity for something like that ### Are there any user-facing changes? No, though we will need to pull it into any point release * Closes: #38752 Authored-by: Jonathan Keane Signed-off-by: Jacob Wujciak-Jens --- r/R/arrow-package.R | 2 +- r/R/install-arrow.R | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/r/R/arrow-package.R b/r/R/arrow-package.R index eec95b8282bfd..1f39a50744abc 100644 --- a/r/R/arrow-package.R +++ b/r/R/arrow-package.R @@ -212,7 +212,7 @@ configure_tzdb <- function() { ) ) } - }) + }, silent = TRUE) } # Clean up the StopSource that was registered in .onLoad() so that if the diff --git a/r/R/install-arrow.R b/r/R/install-arrow.R index 6db6f2b0adaa3..88eb61a5dae76 100644 --- a/r/R/install-arrow.R +++ b/r/R/install-arrow.R @@ -271,6 +271,12 @@ wslify_path <- function(path) { on_rosetta <- function() { # make sure to suppress warnings and ignore the stderr so that this is silent where proc_translated doesn't exist - identical(tolower(Sys.info()[["sysname"]]), "darwin") && - identical(suppressWarnings(system("sysctl -n sysctl.proc_translated", intern = TRUE, ignore.stderr = TRUE)), "1") + sysctl_out <- tryCatch( + suppressWarnings(system("sysctl -n sysctl.proc_translated", intern = TRUE, ignore.stderr = TRUE)), + error = function(e) { + # If this has errored, we assume that this is not on rosetta + return("0") + } + ) + identical(tolower(Sys.info()[["sysname"]]), "darwin") && identical(sysctl_out, "1") }