Skip to content

Commit 2311f34

Browse files
mitc-gjugeclaude
andcommitted
fix(dns): do not report a restored OVH record as lost
restoreRecord had the restore POST and its zone refresh inside one catch. That was harmless while refreshZone swallowed failures, but the previous commit made it throw, which brought a new case into that catch: the restore succeeds and only the publication fails. The message then told the user the record "has been deleted" and to recreate it by hand. It exists at OVH, just unpublished, so following that advice duplicates it as soon as the zone is refreshed. The two failures are now reported separately. A failed POST still means the record is really gone and prints what to recreate. A failed refresh after a successful restore says the record is back but not served yet, and explicitly says not to recreate it. Either way the original replacement error is kept, so the user still learns why the type change failed. Reported by Greptile on Dokploy#5258. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 28f71e7 commit 2311f34

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

‎apps/dokploy/__test__/dns/ovh.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,34 @@ describe("ovhClient.updateRecord", () => {
467467
}),
468468
).rejects.toThrow(/was applied, but refreshing zone "example\.com" failed/);
469469
});
470+
471+
it("does not tell the user to recreate a record that was restored but not published", async () => {
472+
const cfg = freshConfig();
473+
mockApi(
474+
ovhSuccess({
475+
id: 4,
476+
zone: "example.com",
477+
fieldType: "A",
478+
subDomain: "app",
479+
target: "1.1.1.1",
480+
ttl: 60,
481+
}),
482+
ovhSuccess(null), // DELETE de l'ancien
483+
ovhError("Invalid target", 400), // POST de remplacement -> échec
484+
ovhSuccess({ id: 12 }), // POST de restauration -> succès
485+
ovhError("Service unavailable", 503), // refresh -> échec
486+
);
487+
488+
const attempt = ovhClient.updateRecord(cfg, "example.com", "4", {
489+
type: "CNAME",
490+
name: "app.example.com",
491+
content: "not a valid target",
492+
});
493+
494+
// L'enregistrement existe de nouveau chez OVH : le recréer le dupliquerait.
495+
await expect(attempt).rejects.toThrow(/was restored, but refreshing zone/);
496+
await expect(attempt).rejects.not.toThrow(/Recreate it manually/);
497+
});
470498
});
471499

472500
describe("ovhClient.deleteRecord", () => {

‎packages/server/src/utils/dns/ovh.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,19 @@ const refreshZone = async (config: OvhConfig, zone: string) => {
184184
};
185185

186186
// Used to undo the delete half of a type change when the replacement fails.
187+
// The restore and its publication are reported separately: a failed POST means
188+
// the record is really gone, whereas a failed refresh means it is back but not
189+
// served yet. Collapsing the two would tell the user to recreate a record that
190+
// already exists, which duplicates it as soon as the zone is refreshed.
187191
const restoreRecord = async (
188192
config: OvhConfig,
189193
zone: string,
190194
record: OvhRecord,
191195
cause: unknown,
192196
) => {
197+
const causeMessage = cause instanceof Error ? cause.message : String(cause);
198+
const name = toFqdn(record.subDomain, zone);
199+
193200
try {
194201
await ovhFetch(config, `/domain/zone/${encodeURIComponent(zone)}/record`, {
195202
method: "POST",
@@ -200,13 +207,17 @@ const restoreRecord = async (
200207
...(record.ttl === null ? {} : { ttl: record.ttl }),
201208
},
202209
});
210+
} catch {
211+
throw new Error(
212+
`OVH: could not replace the record and could not restore the original one, which has been deleted. Recreate it manually: ${record.fieldType} ${name} -> ${record.target}. Original failure: ${causeMessage}`,
213+
);
214+
}
215+
216+
try {
203217
await refreshZone(config, zone);
204218
} catch {
205-
const name = toFqdn(record.subDomain, zone);
206219
throw new Error(
207-
`OVH: could not replace the record and could not restore the original one, which has been deleted. Recreate it manually: ${record.fieldType} ${name} -> ${record.target}. Original failure: ${
208-
cause instanceof Error ? cause.message : String(cause)
209-
}`,
220+
`OVH: the replacement failed and the original record was restored, but refreshing zone "${zone}" failed, so the restore is not served yet. Do not recreate it — the next successful change to this zone will publish it. Original failure: ${causeMessage}`,
210221
);
211222
}
212223
};

0 commit comments

Comments
 (0)