Skip to content

Commit c99ac47

Browse files
authored
fix(R): detect x64 R on Windows ARM via exit codes (#13822)
* fix: detect x64 R on Windows ARM via exit codes When x64 R crashes on Windows ARM, detect specific exit codes and provide helpful error message instead of generic "check your R installation". Detects two crash scenarios: - Native ARM hardware: -1073741569 (STATUS_NOT_SUPPORTED) - Windows ARM VM on Mac: -1073741819 (STATUS_ACCESS_VIOLATION) Both occur when rmarkdown package loads under x64 emulation. R script completes successfully and produces YAML before crashing during cleanup. These error codes are unique to x64 R on ARM Windows, so checking them directly is sufficient without needing to verify ARM hardware via Windows API. Closes #8730 Related: #13790 * docs: add issue and test repo links to ARM detection comment Add references to issue #8730 and quarto-windows-arm test repository in code comments to help future contributors understand the context. * fix: improve Windows ARM x64 R error message Make error message more actionable: - Show detected error code - Explain x64 R on Windows ARM issue - Provide step-by-step fix instructions - Link to issue #8730 for context * fix: prevent duplicate Windows ARM x64 R error message Use errorOnce() instead of rethrowing WindowsArmX64RError to prevent duplicate error messages when printCallRDiagnostics() calls knitrCapabilities() again. Returns undefined like other knitrCapabilities errors without changing general error handling in callR(). * refactor: extract x64-on-ARM check into throwIfX64ROnArm() Extract x64 R crash detection into helper function for better code organization. Function name clearly indicates it throws on detection. * docs: add changelog entry for Windows ARM x64 R detection
1 parent f82f02d commit c99ac47

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

news/changelog-1.9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ All changes included in 1.9:
100100

101101
## Other fixes and improvements
102102

103+
- ([#8730](https://github.com/quarto-dev/quarto-cli/issues/8730)): Detect x64 R crashes on Windows ARM and provide helpful error message directing users to install native ARM64 R instead of showing generic "check your R installation" error.
103104
- ([#13402](https://github.com/quarto-dev/quarto-cli/issues/13402)): `nfpm` (<https://nfpm.goreleaser.com/>) is now used to create the `.deb` package, and new `.rpm` package. Both Linux packages are also now built for `x86_64` (`amd64`) and `aarch64` (`arm64`) architectures.
104105
- ([#13528](https://github.com/quarto-dev/quarto-cli/pull/13528)): Adds support for table specification using nested lists and the `list-table` class.
105106
- ([#13575](https://github.com/quarto-dev/quarto-cli/pull/13575)): Improve CPU architecture detection/reporting in macOS to allow quarto to run in virtualized environments such as OpenAI's `codex`.

src/core/knitr.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { rBinaryPath, resourcePath } from "./resources.ts";
1111
import { readYamlFromString } from "./yaml.ts";
1212
import { coerce, satisfies } from "semver/mod.ts";
1313
import { debug } from "../deno_ral/log.ts";
14+
import { errorOnce } from "./log.ts";
1415

1516
export interface KnitrCapabilities {
1617
versionMajor: number;
@@ -68,6 +69,36 @@ export async function checkRBinary() {
6869
}
6970
}
7071

72+
export class WindowsArmX64RError extends Error {
73+
constructor(msg: string) {
74+
super(msg);
75+
}
76+
}
77+
78+
// Check for x64 R crashes on ARM Windows
79+
// These specific error codes only occur when x64 R crashes on ARM Windows
80+
// See: https://github.com/quarto-dev/quarto-cli/issues/8730
81+
// https://github.com/cderv/quarto-windows-arm
82+
function throwIfX64ROnArm(exitCode: number): void {
83+
const isX64RCrashOnArm =
84+
exitCode === -1073741569 || // STATUS_NOT_SUPPORTED (native ARM hardware)
85+
exitCode === -1073741819; // STATUS_ACCESS_VIOLATION (Windows ARM VM on Mac)
86+
87+
if (isX64RCrashOnArm) {
88+
throw new WindowsArmX64RError(
89+
`R process crashed with known error code (${exitCode}).\n\n` +
90+
"This typically indicates x64 R running on Windows 11 ARM.\n" +
91+
"x64 R runs under emulation and is not reliable for Quarto.\n\n" +
92+
"To fix this issue:\n" +
93+
"1. Check your R version with: Rscript -e \"R.version$platform\"\n" +
94+
"2. If it shows 'x86_64-w64-mingw32', you need ARM64 R\n" +
95+
"3. Install native ARM64 R: https://blog.r-project.org/2024/04/23/r-on-64-bit-arm-windows/\n" +
96+
"4. If needed, set QUARTO_R environment variable to point to ARM64 Rscript\n\n" +
97+
"More context on this issue: https://github.com/quarto-dev/quarto-cli/issues/8730",
98+
);
99+
}
100+
}
101+
71102
export async function knitrCapabilities(rBin: string | undefined) {
72103
if (!rBin) return undefined;
73104
try {
@@ -115,9 +146,17 @@ export async function knitrCapabilities(rBin: string | undefined) {
115146
if (result.stderr) {
116147
debug(` with stderr from R:\n${result.stderr}`);
117148
}
149+
150+
throwIfX64ROnArm(result.code);
151+
152+
return undefined;
153+
}
154+
} catch (e) {
155+
// Log x64-on-ARM errors once, then return undefined like other errors
156+
if (e instanceof WindowsArmX64RError) {
157+
errorOnce(e.message);
118158
return undefined;
119159
}
120-
} catch {
121160
debug(
122161
`\n++ Error while running 'capabilities/knitr.R' ${
123162
rBin ? "with " + rBin : ""

0 commit comments

Comments
 (0)