Skip to content

Commit 97db300

Browse files
authored
fix(secrets): type missing plan errors
1 parent bff83b5 commit 97db300

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

‎src/cli/secrets-cli.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,24 @@ describe("secrets CLI", () => {
412412
expect(runSecretsApply).not.toHaveBeenCalled();
413413
});
414414

415+
it("preserves causes for unrelated apply errors with a similar message", async () => {
416+
await withPlanFile(async (planPath) => {
417+
runSecretsApply.mockRejectedValueOnce(
418+
new Error("Secrets plan file not found during apply", {
419+
cause: new Error("provider diagnostic"),
420+
}),
421+
);
422+
423+
await expect(
424+
createProgram().parseAsync(["secrets", "apply", "--from", planPath], { from: "user" }),
425+
).rejects.toThrow("__exit__:1");
426+
427+
expect(runtimeErrors.join("\n")).toContain(
428+
"Secrets plan file not found during apply | provider diagnostic",
429+
);
430+
});
431+
});
432+
415433
it("does not print skipped-exec note when apply dry-run skippedExecRefs is zero", async () => {
416434
await withPlanFile(async (planPath) => {
417435
runSecretsApply.mockResolvedValue(createSecretsApplyResult({ resolvabilityComplete: false }));

‎src/cli/secrets-cli.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const secretsApplyLoader = createLazyImportLoader<SecretsApplyModule>(
4646
() => import("../secrets/apply.js"),
4747
);
4848

49+
class SecretsPlanFileNotFoundError extends Error {}
50+
4951
async function readPlanFile(pathname: string): Promise<SecretsApplyPlan> {
5052
// Apply consumes a generated plan shape, not arbitrary JSON.
5153
const [{ readFileSync }, { isSecretsApplyPlan }] = await Promise.all([
@@ -57,7 +59,9 @@ async function readPlanFile(pathname: string): Promise<SecretsApplyPlan> {
5759
raw = readFileSync(pathname, "utf8");
5860
} catch (err) {
5961
if (hasErrnoCode(err, "ENOENT")) {
60-
throw new Error(`Secrets plan file not found: ${pathname}`, { cause: err });
62+
throw new SecretsPlanFileNotFoundError(`Secrets plan file not found: ${pathname}`, {
63+
cause: err,
64+
});
6165
}
6266
throw err;
6367
}
@@ -341,10 +345,10 @@ export function registerSecretsCli(program: Command): void {
341345
: "Secrets apply: no changes.",
342346
);
343347
} catch (err) {
344-
// The missing-plan wrapper already carries a user-friendly message; keep its
345-
// ENOENT cause out of the rendered CLI output while preserving it for diagnostics.
348+
// The missing-plan wrapper already carries a user-facing message. Keep its
349+
// ENOENT cause available to diagnostics without rendering the raw filesystem error.
346350
const message =
347-
err instanceof Error && err.message.startsWith("Secrets plan file not found")
351+
err instanceof SecretsPlanFileNotFoundError
348352
? err.message
349353
: formatErrorMessage(err);
350354
defaultRuntime.error(

0 commit comments

Comments
 (0)