Skip to content

Commit 4cff81a

Browse files
committed
fix(mobile): preserve prebuild errors when cache recovery fails
1 parent 91708f5 commit 4cff81a

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

‎scripts/mobile-native-client.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,61 @@ it.layer(NodeServices.layer)("Android clean prebuild", (it) => {
193193
}),
194194
);
195195

196+
it.effect("preserves the original failure when cache recovery also fails", () =>
197+
Effect.gen(function* () {
198+
for (const phase of ["prebuild", "save"]) {
199+
const { fs, mobile, file, regenerate, path } = yield* fixture;
200+
const saveFailure = PlatformError.systemError({
201+
_tag: "PermissionDenied",
202+
module: "FileSystem",
203+
method: "rename",
204+
description: "save failed",
205+
});
206+
const original =
207+
phase === "prebuild"
208+
? new NativeClientError({ message: "prebuild failed" })
209+
: saveFailure;
210+
const restoreFailure = PlatformError.systemError({
211+
_tag: "PermissionDenied",
212+
module: "FileSystem",
213+
method: "rename",
214+
description: "restore failed",
215+
});
216+
const failingFs = {
217+
...fs,
218+
rename: (source: string, target: string) =>
219+
target === file(".gradle")
220+
? Effect.fail(restoreFailure)
221+
: phase === "save" && source === file("app/.cxx")
222+
? Effect.fail(saveFailure)
223+
: fs.rename(source, target),
224+
};
225+
const error = yield* prebuildAndroid(
226+
mobile,
227+
regenerate.pipe(Effect.andThen(Effect.fail(original))),
228+
).pipe(Effect.provideService(FileSystem.FileSystem, failingFs), Effect.flip);
229+
assert.strictEqual(error, original);
230+
const saved = (yield* fs.readDirectory(mobile)).find((name) =>
231+
name.startsWith(".android-prebuild-"),
232+
);
233+
assert.isDefined(saved);
234+
const recovery = path.join(mobile, saved!);
235+
assert.strictEqual(
236+
yield* fs.readFileString(path.join(recovery, ".gradle/history")),
237+
".gradle/history",
238+
);
239+
assert.isTrue(
240+
(yield* TestConsole.errorLines).some(
241+
(line) =>
242+
typeof line === "string" &&
243+
line.includes(recovery) &&
244+
line.includes("restore failed"),
245+
),
246+
);
247+
}
248+
}).pipe(Effect.provide(TestConsole.layer)),
249+
);
250+
196251
it.effect("restores saved outputs when prebuild is interrupted", () =>
197252
Effect.gen(function* () {
198253
const { fs, mobile, file, regenerate } = yield* fixture;

‎scripts/mobile-native-client.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export const prebuildAndroid = Effect.fn("nativeClient.prebuildAndroid")(functio
333333
yield* restore(prebuild);
334334
}),
335335
);
336-
yield* Effect.gen(function* () {
336+
const recovered = yield* Effect.gen(function* () {
337337
for (const cache of caches) {
338338
const source = path.join(saved, cache);
339339
if (!(yield* fs.exists(source))) continue;
@@ -361,9 +361,11 @@ export const prebuildAndroid = Effect.fn("nativeClient.prebuildAndroid")(functio
361361
// Pending interruption can suppress the returned error when the mask ends.
362362
// Print the recovery path before leaving uninterruptible cleanup.
363363
Effect.tapError((error) => Console.error(error.message)),
364+
Effect.exit,
364365
);
365-
yield* fs.remove(saved, { recursive: true });
366+
if (Exit.isSuccess(recovered)) yield* fs.remove(saved, { recursive: true });
366367
if (Exit.isFailure(result)) return yield* Effect.failCause(result.cause);
368+
if (Exit.isFailure(recovered)) return yield* Effect.failCause(recovered.cause);
367369
}),
368370
);
369371
});

0 commit comments

Comments
 (0)