Skip to content

Commit 1765bdd

Browse files
committed
refactor: extract x64-on-ARM check into throwIfX64ROnArm()
Extract the x64 R crash detection logic into a helper function for better code organization. Function name clearly indicates it throws an error if the condition is met.
1 parent 18b393a commit 1765bdd

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/core/knitr.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,30 @@ export class WindowsArmX64RError extends Error {
7575
}
7676
}
7777

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+
78102
export async function knitrCapabilities(rBin: string | undefined) {
79103
if (!rBin) return undefined;
80104
try {
@@ -123,27 +147,7 @@ export async function knitrCapabilities(rBin: string | undefined) {
123147
debug(` with stderr from R:\n${result.stderr}`);
124148
}
125149

126-
// Check for x64 R crashes on ARM Windows
127-
// These specific error codes only occur when x64 R crashes on ARM Windows
128-
// See: https://github.com/quarto-dev/quarto-cli/issues/8730
129-
// https://github.com/cderv/quarto-windows-arm
130-
const isX64RCrashOnArm =
131-
result.code === -1073741569 || // STATUS_NOT_SUPPORTED (native ARM hardware)
132-
result.code === -1073741819; // STATUS_ACCESS_VIOLATION (Windows ARM VM on Mac)
133-
134-
if (isX64RCrashOnArm) {
135-
throw new WindowsArmX64RError(
136-
`R process crashed with known error code (${result.code}).\n\n` +
137-
"This typically indicates x64 R running on Windows 11 ARM.\n" +
138-
"x64 R runs under emulation and is not reliable for Quarto.\n\n" +
139-
"To fix this issue:\n" +
140-
"1. Check your R version with: Rscript -e \"R.version$platform\"\n" +
141-
"2. If it shows 'x86_64-w64-mingw32', you need ARM64 R\n" +
142-
"3. Install native ARM64 R: https://blog.r-project.org/2024/04/23/r-on-64-bit-arm-windows/\n" +
143-
"4. If needed, set QUARTO_R environment variable to point to ARM64 Rscript\n\n" +
144-
"More context on this issue: https://github.com/quarto-dev/quarto-cli/issues/8730",
145-
);
146-
}
150+
throwIfX64ROnArm(result.code);
147151

148152
return undefined;
149153
}

0 commit comments

Comments
 (0)