Skip to content

Commit fdb7f2e

Browse files
committed
fix(R): 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. This is the simplest possible approach: just check exit codes, no DLL calls. Closes #8730 Related: #13790
1 parent b323477 commit fdb7f2e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/core/knitr.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ export async function checkRBinary() {
6868
}
6969
}
7070

71+
export class WindowsArmX64RError extends Error {
72+
constructor(msg: string) {
73+
super(msg);
74+
}
75+
}
76+
7177
export async function knitrCapabilities(rBin: string | undefined) {
7278
if (!rBin) return undefined;
7379
try {
@@ -115,9 +121,30 @@ export async function knitrCapabilities(rBin: string | undefined) {
115121
if (result.stderr) {
116122
debug(` with stderr from R:\n${result.stderr}`);
117123
}
124+
125+
// Check for x64 R crashes on ARM Windows
126+
// These specific error codes only occur when x64 R crashes on ARM Windows
127+
const isX64RCrashOnArm =
128+
result.code === -1073741569 || // STATUS_NOT_SUPPORTED (native ARM hardware)
129+
result.code === -1073741819; // STATUS_ACCESS_VIOLATION (Windows ARM VM on Mac)
130+
131+
if (isX64RCrashOnArm) {
132+
throw new WindowsArmX64RError(
133+
"x64 R detected on Windows ARM.\n\n" +
134+
"x64 R runs under emulation and is not reliable for Quarto.\n" +
135+
"Please install native ARM64 R. \n" +
136+
"Read about R on 64-bit Windows ARM at https://blog.r-project.org/2024/04/23/r-on-64-bit-arm-windows/\n" +
137+
"After installation, set QUARTO_R environment variable if the correct version is not correctly found.",
138+
);
139+
}
140+
118141
return undefined;
119142
}
120-
} catch {
143+
} catch (e) {
144+
// Rethrow x64-on-ARM errors - these have helpful messages
145+
if (e instanceof WindowsArmX64RError) {
146+
throw e;
147+
}
121148
debug(
122149
`\n++ Error while running 'capabilities/knitr.R' ${
123150
rBin ? "with " + rBin : ""

0 commit comments

Comments
 (0)