Skip to content

Commit 8669ef6

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. This simpler approach checks exit codes directly rather than parsing YAML output to detect architecture strings. Closes #8730 Related: #13790
1 parent b323477 commit 8669ef6

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/core/knitr.ts

Lines changed: 29 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 { isWindowsArm } from "./windows.ts";
1415

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

72+
export class WindowsArmX64RError extends Error {
73+
constructor(msg: string) {
74+
super(msg);
75+
}
76+
}
77+
7178
export async function knitrCapabilities(rBin: string | undefined) {
7279
if (!rBin) return undefined;
7380
try {
@@ -115,9 +122,30 @@ export async function knitrCapabilities(rBin: string | undefined) {
115122
if (result.stderr) {
116123
debug(` with stderr from R:\n${result.stderr}`);
117124
}
125+
126+
// Check for x64 R crashes on ARM Windows
127+
const isX64RCrashOnArm = isWindowsArm() && (
128+
result.code === -1073741569 || // STATUS_NOT_SUPPORTED (native ARM hardware)
129+
result.code === -1073741819 // STATUS_ACCESS_VIOLATION (Windows ARM VM on Mac)
130+
);
131+
132+
if (isX64RCrashOnArm) {
133+
throw new WindowsArmX64RError(
134+
"x64 R detected on Windows ARM.\n\n" +
135+
"x64 R runs under emulation and is not reliable for Quarto.\n" +
136+
"Please install native ARM64 R. \n" +
137+
"Read about R on 64-bit Windows ARM at https://blog.r-project.org/2024/04/23/r-on-64-bit-arm-windows/\n" +
138+
"After installation, set QUARTO_R environment variable if the correct version is not correctly found.",
139+
);
140+
}
141+
118142
return undefined;
119143
}
120-
} catch {
144+
} catch (e) {
145+
// Rethrow x64-on-ARM errors - these have helpful messages
146+
if (e instanceof WindowsArmX64RError) {
147+
throw e;
148+
}
121149
debug(
122150
`\n++ Error while running 'capabilities/knitr.R' ${
123151
rBin ? "with " + rBin : ""

0 commit comments

Comments
 (0)