Skip to content

Commit

Permalink
GH-38752: [R] Wrap rosetta detection in tryCatch (#38754)
Browse files Browse the repository at this point in the history
### 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 <[email protected]>
Signed-off-by: Jacob Wujciak-Jens <[email protected]>
  • Loading branch information
jonkeane authored Nov 17, 2023
1 parent 1fd11d3 commit e543ee6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion r/R/arrow-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ configure_tzdb <- function() {
)
)
}
})
}, silent = TRUE)
}

# Clean up the StopSource that was registered in .onLoad() so that if the
Expand Down
10 changes: 8 additions & 2 deletions r/R/install-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit e543ee6

Please sign in to comment.