fix(cli): scoping android instrumentation-hook diagnosis to real platform signal (#10028)

This commit is contained in:
Markus Hartung
2026-08-21 20:00:40 -03:00
parent 3caa59107e
commit 17b35f67d9
3 changed files with 23 additions and 4 deletions

View File

@@ -94,10 +94,15 @@ export function ensureAndroidCacheDir(options = {}) {
*/
export function isFatalInstrumentationHookFailure(text) {
if (!text) return false;
return (
/Unsupported platform:\s*android/i.test(text) ||
/error occurred while loading instrumentation hook/i.test(text)
);
// Next.js wraps ANY throw inside instrumentation.register() with the generic
// "An error occurred while loading instrumentation hook:" prefix, on every
// platform (node_modules/next/dist/server/web/globals.js). That prefix alone
// therefore cannot identify the Android/Termux cache-probe failure — a bare
// generic instrumentation error on win32/desktop would be misreported as the
// Android bug and hide the real cause. Only match when the text actually
// carries the Android platform marker that Next's getCacheDirectory() emits.
// #10028
return /Unsupported platform:\s*android/i.test(text);
}
/**

View File

@@ -0,0 +1 @@
- fix(cli): stop diagnosing every Next.js instrumentation-hook failure as the Android/Termux cache bug — only the Android "Unsupported platform: android" signal now triggers the Android hint, so a win32/desktop instrumentation error surfaces its real cause instead of a useless `mkdir -p ~/.cache` (#10028)

View File

@@ -166,6 +166,19 @@ test("isFatalInstrumentationHookFailure: matches Next.js android + hook errors",
assert.equal(isFatalInstrumentationHookFailure(""), false);
});
test("isFatalInstrumentationHookFailure: BUG #10028 — generic non-Android instrumentation failure is not Android/Termux", () => {
// Next.js wraps ANY throw inside instrumentation.register() with the generic
// "An error occurred while loading instrumentation hook:" prefix, on every
// platform. Without an actual Android/"Unsupported platform:" signal, that
// generic wrapper must NOT be diagnosed as the Android/Termux cache-dir bug,
// or a plain win32/desktop failure gets a useless `mkdir -p ~/.cache` hint
// and the real cause is hidden.
const genericWindowsFailure =
"Error: An error occurred while loading instrumentation hook: " +
"Cannot find module 'C:\\Users\\dev\\.omniroute\\config.json'";
assert.equal(isFatalInstrumentationHookFailure(genericWindowsFailure), false);
});
test("formatAndroidInstrumentationFailureHint: names the cache dir and TERMUX_GUIDE", () => {
const hint = formatAndroidInstrumentationFailureHint("/data/home/.cache");
assert.match(hint, /\/data\/home\/\.cache/);