gencow 0.1.284 → 0.1.286
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dashboard/assets/{index-CpQz6uv1.js → index-BnBn8uo4.js} +1 -1
- package/dashboard/index.html +1 -1
- package/lib/app-command.mjs +73 -4
- package/lib/app-response-error.mjs +27 -0
- package/lib/cli-command-runner.mjs +5 -0
- package/lib/db-check-deadline.mjs +50 -0
- package/lib/db-push-command.mjs +58 -21
- package/lib/deploy-admission-boundary.mjs +18 -1
- package/lib/deploy-admission-transport-failure.mjs +148 -0
- package/lib/deploy-app-target.mjs +82 -13
- package/lib/deploy-codegen-failure.mjs +36 -4
- package/lib/deploy-command.mjs +8 -2
- package/lib/deploy-failure-diagnostic.mjs +33 -2
- package/lib/deploy-package-runtime.mjs +3 -3
- package/lib/deploy-runtime.mjs +16 -1
- package/lib/deployment-admission-retry.mjs +6 -1
- package/lib/migration-diagnostic.mjs +27 -7
- package/lib/platform-client.mjs +3 -2
- package/lib/prod-create-auth-diagnostic.mjs +62 -13
- package/lib/static-deploy-command.mjs +3 -0
- package/package.json +3 -3
- package/runtime/server.mjs +242 -201
- package/runtime/tooling.mjs +123 -38
- package/scripts/tooling-codegen-runtime.ts +122 -6
package/dashboard/index.html
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
<link rel="icon" type="image/png" sizes="32x32" href="/_dashboard/favicon-32.png" />
|
|
24
24
|
<link rel="icon" type="image/png" sizes="16x16" href="/_dashboard/favicon-16.png" />
|
|
25
25
|
<link rel="apple-touch-icon" sizes="180x180" href="/_dashboard/apple-touch-icon.png" />
|
|
26
|
-
<script type="module" crossorigin src="/_dashboard/assets/index-
|
|
26
|
+
<script type="module" crossorigin src="/_dashboard/assets/index-BnBn8uo4.js"></script>
|
|
27
27
|
<link rel="stylesheet" crossorigin href="/_dashboard/assets/index-C6-BpKKR.css">
|
|
28
28
|
</head>
|
|
29
29
|
<body class="antialiased">
|
package/lib/app-command.mjs
CHANGED
|
@@ -22,6 +22,9 @@ import { resolveProjectMetadataPath, resolveProjectSelection } from "./project-c
|
|
|
22
22
|
import { updateEnvLocalUrl } from "./cli-project-runtime.mjs";
|
|
23
23
|
|
|
24
24
|
const DEFAULT_APP_CREATE_TIMEOUT_MS = 60_000;
|
|
25
|
+
const DEFAULT_APP_QUERY_TIMEOUT_MS = 30_000;
|
|
26
|
+
const APP_QUERY_TIMED_OUT = Symbol("app-query-timed-out");
|
|
27
|
+
const SAFE_APP_NAME_FOR_COMMAND = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
|
|
25
28
|
const SAFE_CLI_OPTION_PATTERN = /^--?[A-Za-z][A-Za-z0-9-]{0,40}$/u;
|
|
26
29
|
|
|
27
30
|
function resolveAppCreateTimeoutMs(value) {
|
|
@@ -31,6 +34,25 @@ function resolveAppCreateTimeoutMs(value) {
|
|
|
31
34
|
: DEFAULT_APP_CREATE_TIMEOUT_MS;
|
|
32
35
|
}
|
|
33
36
|
|
|
37
|
+
function resolveAppQueryTimeoutMs(value) {
|
|
38
|
+
const parsed = Number(value);
|
|
39
|
+
return Number.isSafeInteger(parsed) && parsed >= 100 && parsed <= 600_000
|
|
40
|
+
? parsed
|
|
41
|
+
: DEFAULT_APP_QUERY_TIMEOUT_MS;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Read-only query timeout: nothing is changed, so the user can simply retry the same lookup. */
|
|
45
|
+
function formatAppQueryTimeoutDiagnostic({ operation, timeoutMs, retryCommand }) {
|
|
46
|
+
return [
|
|
47
|
+
`The Gencow Platform did not respond to "${operation}" within ${timeoutMs}ms.`,
|
|
48
|
+
"Code: CLI_PLATFORM_TIMEOUT",
|
|
49
|
+
`Stage: ${operation}`,
|
|
50
|
+
"State: nothing was changed; this is a read-only lookup.",
|
|
51
|
+
"Retryable: yes",
|
|
52
|
+
`Retry: ${retryCommand}`,
|
|
53
|
+
].join("\n");
|
|
54
|
+
}
|
|
55
|
+
|
|
34
56
|
function appResponseStatus(response) {
|
|
35
57
|
return Number.isSafeInteger(response?.status) ? `HTTP ${response.status}` : "unknown HTTP status";
|
|
36
58
|
}
|
|
@@ -231,6 +253,7 @@ async function confirmDelete(name) {
|
|
|
231
253
|
|
|
232
254
|
export function createAppCommand({
|
|
233
255
|
appCreateTimeoutMs = resolveAppCreateTimeoutMs(process.env.GENCOW_APP_CREATE_TIMEOUT_MS),
|
|
256
|
+
appQueryTimeoutMs = resolveAppQueryTimeoutMs(process.env.GENCOW_APP_QUERY_TIMEOUT_MS),
|
|
234
257
|
clearTimeoutImpl = clearTimeout,
|
|
235
258
|
confirmDeleteImpl = confirmDelete,
|
|
236
259
|
createAbortControllerImpl = () => new AbortController(),
|
|
@@ -251,6 +274,29 @@ export function createAppCommand({
|
|
|
251
274
|
warnImpl = warn,
|
|
252
275
|
}) {
|
|
253
276
|
const boundedAppCreateTimeoutMs = resolveAppCreateTimeoutMs(appCreateTimeoutMs);
|
|
277
|
+
const boundedAppQueryTimeoutMs = resolveAppQueryTimeoutMs(appQueryTimeoutMs);
|
|
278
|
+
|
|
279
|
+
// Resolves to APP_QUERY_TIMED_OUT when the Platform stays silent past the deadline.
|
|
280
|
+
// The query is aborted so no lingering request outlives the command.
|
|
281
|
+
async function requestAppQuery(creds, queryName, args) {
|
|
282
|
+
const controller = createAbortControllerImpl();
|
|
283
|
+
let timeoutHandle;
|
|
284
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
285
|
+
timeoutHandle = setTimeoutImpl(() => {
|
|
286
|
+
controller.abort();
|
|
287
|
+
resolve(APP_QUERY_TIMED_OUT);
|
|
288
|
+
}, boundedAppQueryTimeoutMs);
|
|
289
|
+
});
|
|
290
|
+
try {
|
|
291
|
+
const request = (async () => {
|
|
292
|
+
const response = await rpcQueryImpl(creds, queryName, args, { signal: controller.signal });
|
|
293
|
+
return { response, decoded: await readJsonValueResponse(response) };
|
|
294
|
+
})();
|
|
295
|
+
return await Promise.race([request, timeoutPromise]);
|
|
296
|
+
} finally {
|
|
297
|
+
clearTimeoutImpl(timeoutHandle);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
254
300
|
|
|
255
301
|
async function requestAppCreate(creds, name) {
|
|
256
302
|
const controller = createAbortControllerImpl();
|
|
@@ -291,8 +337,19 @@ export function createAppCommand({
|
|
|
291
337
|
|
|
292
338
|
if (!subcmd || subcmd === "list") {
|
|
293
339
|
logImpl(`\n${BOLD}${CYAN}Your Apps${RESET}\n`);
|
|
294
|
-
const
|
|
295
|
-
|
|
340
|
+
const queried = await requestAppQuery(creds, "apps.list");
|
|
341
|
+
if (queried === APP_QUERY_TIMED_OUT) {
|
|
342
|
+
errorImpl(
|
|
343
|
+
formatAppQueryTimeoutDiagnostic({
|
|
344
|
+
operation: "app list",
|
|
345
|
+
timeoutMs: boundedAppQueryTimeoutMs,
|
|
346
|
+
retryCommand: "gencow app list",
|
|
347
|
+
}),
|
|
348
|
+
);
|
|
349
|
+
return 1;
|
|
350
|
+
}
|
|
351
|
+
const { response: res, decoded } = queried;
|
|
352
|
+
const body = decoded.parsed ? decoded.value : null;
|
|
296
353
|
if (!res.ok) {
|
|
297
354
|
errorImpl(appResponseError(body, invalidAppResponse("app list", res, "error"), res));
|
|
298
355
|
return 1;
|
|
@@ -499,8 +556,20 @@ ${dashboardLine}
|
|
|
499
556
|
errorImpl("Usage: gencow app status <name>");
|
|
500
557
|
return 1;
|
|
501
558
|
}
|
|
502
|
-
const
|
|
503
|
-
|
|
559
|
+
const queried = await requestAppQuery(creds, "apps.get", { name });
|
|
560
|
+
if (queried === APP_QUERY_TIMED_OUT) {
|
|
561
|
+
errorImpl(
|
|
562
|
+
formatAppQueryTimeoutDiagnostic({
|
|
563
|
+
operation: "app status",
|
|
564
|
+
timeoutMs: boundedAppQueryTimeoutMs,
|
|
565
|
+
retryCommand: SAFE_APP_NAME_FOR_COMMAND.test(name)
|
|
566
|
+
? `gencow app status ${name}`
|
|
567
|
+
: "gencow app status <name>",
|
|
568
|
+
}),
|
|
569
|
+
);
|
|
570
|
+
return 1;
|
|
571
|
+
}
|
|
572
|
+
const { response: res, decoded } = queried;
|
|
504
573
|
const body = decoded.parsed ? decoded.value : null;
|
|
505
574
|
if (!res.ok) {
|
|
506
575
|
errorImpl(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formatLatestCliInvocation } from "./cli-update-guidance.mjs";
|
|
2
|
+
import { authCauseNextAction, safeAuthCauseCode } from "./release-auth-cause.mjs";
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
5
|
APP_DELETE_OPERATION_PATTERN,
|
|
@@ -39,6 +40,31 @@ const USER_ACTIONS = new Set([
|
|
|
39
40
|
"WAIT",
|
|
40
41
|
]);
|
|
41
42
|
|
|
43
|
+
// Only a credential the Platform refused (CLI_AUTH_REQUIRED, stage "auth", not retryable) gets the login-check
|
|
44
|
+
// rendering. Other stage "auth" responses (for example a suspended account) keep the generic path, because a
|
|
45
|
+
// login retry would misattribute the cause. The safe cause is shown only when it is a known enum.
|
|
46
|
+
function isTypedAuthRejection(body) {
|
|
47
|
+
return (
|
|
48
|
+
body.code === "CLI_AUTH_REQUIRED" &&
|
|
49
|
+
body.stage === "auth" &&
|
|
50
|
+
body.retryable !== true
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function formatTypedAuthRejectionLines(body) {
|
|
55
|
+
const message = typeof body.error === "string" && body.error.trim() ? body.error.trim() : "CLI authentication is required";
|
|
56
|
+
const lines = [message, `Code: ${body.code}`];
|
|
57
|
+
const cause = safeAuthCauseCode(body.causeCode);
|
|
58
|
+
if (cause) lines.push(`Cause: ${cause}`);
|
|
59
|
+
if (body.stateChanged === false) lines.push("Changed: nothing");
|
|
60
|
+
lines.push("Retryable: no");
|
|
61
|
+
if (/^[A-Za-z0-9_-]{8,128}$/u.test(body.correlationId ?? "")) {
|
|
62
|
+
lines.push(`Correlation ID: ${body.correlationId}`);
|
|
63
|
+
}
|
|
64
|
+
lines.push(`Next: ${authCauseNextAction()}`);
|
|
65
|
+
return lines;
|
|
66
|
+
}
|
|
67
|
+
|
|
42
68
|
export function appResponseError(body, fallback, response = null, options = {}) {
|
|
43
69
|
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
44
70
|
if (response?.status === 503) {
|
|
@@ -46,6 +72,7 @@ export function appResponseError(body, fallback, response = null, options = {})
|
|
|
46
72
|
}
|
|
47
73
|
return fallback;
|
|
48
74
|
}
|
|
75
|
+
if (isTypedAuthRejection(body)) return formatTypedAuthRejectionLines(body).join("\n");
|
|
49
76
|
const blockedDeleteDiagnostic = readBlockedAppDeleteDiagnostic(body, options.expectedAppId);
|
|
50
77
|
if (blockedDeleteDiagnostic) {
|
|
51
78
|
return formatBlockedAppDeleteDiagnosticLines(blockedDeleteDiagnostic).join("\n");
|
|
@@ -10,6 +10,10 @@ import {
|
|
|
10
10
|
HINTS_DATA_LOSS_NOTICE,
|
|
11
11
|
SAFE_COLUMN_REFERENCE,
|
|
12
12
|
} from "./migration-hints.mjs";
|
|
13
|
+
import {
|
|
14
|
+
isAdmissionTransportFailure,
|
|
15
|
+
renderAdmissionTransportFailureLines,
|
|
16
|
+
} from "./deploy-admission-transport-failure.mjs";
|
|
13
17
|
|
|
14
18
|
const SAFE_CORRELATION_ID = /^[A-Za-z0-9_-]{8,128}$/u;
|
|
15
19
|
const SAFE_APP_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
|
|
@@ -330,6 +334,7 @@ export function formatCommandError(caught) {
|
|
|
330
334
|
}
|
|
331
335
|
|
|
332
336
|
function commandErrorMessage(caught) {
|
|
337
|
+
if (isAdmissionTransportFailure(caught)) return renderAdmissionTransportFailureLines(caught).join("\n");
|
|
333
338
|
const procedureDiagnostic = formatProcedureRpcDiagnostic(caught);
|
|
334
339
|
if (procedureDiagnostic) return procedureDiagnostic;
|
|
335
340
|
const localDiagnostic = SAFE_LOCAL_ERROR_CODES.get(caught?.code);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Bounded request deadline for read-only db:check and db:check --inspect-state requests.
|
|
2
|
+
// db:push never uses this: a write whose outcome is unknown must keep the receipt recovery flow.
|
|
3
|
+
|
|
4
|
+
const DEFAULT_DB_CHECK_TIMEOUT_MS = 60_000;
|
|
5
|
+
export const DEADLINE_EXCEEDED = Symbol("db-check-deadline-exceeded");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Out-of-range or non-numeric values fall back to the given default, matching the app query deadline policy.
|
|
9
|
+
* Shared by every read-only request deadline (db:check, deploy target lookup) so the range rule has one owner.
|
|
10
|
+
*/
|
|
11
|
+
export function resolveReadOnlyDeadlineMs(value, defaultMs) {
|
|
12
|
+
const parsed = Number(value);
|
|
13
|
+
return Number.isSafeInteger(parsed) && parsed >= 100 && parsed <= 600_000 ? parsed : defaultMs;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function resolveDbCheckTimeoutMs(value) {
|
|
17
|
+
return resolveReadOnlyDeadlineMs(value, DEFAULT_DB_CHECK_TIMEOUT_MS);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Upper bound for a read-only db:check / db:check --inspect-state request. Only the check path uses this:
|
|
22
|
+
* a db:push outcome can be ambiguous after a silent wait, so pushes keep the receipt recovery flow unbounded.
|
|
23
|
+
*/
|
|
24
|
+
export function createReadOnlyCheckDeadline(timeoutMs) {
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
let timer;
|
|
27
|
+
let timedOut = false;
|
|
28
|
+
const expired = new Promise((resolve) => {
|
|
29
|
+
timer = setTimeout(() => {
|
|
30
|
+
timedOut = true;
|
|
31
|
+
controller.abort(new Error("db:check request deadline exceeded"));
|
|
32
|
+
resolve(DEADLINE_EXCEEDED);
|
|
33
|
+
}, timeoutMs);
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
signal: controller.signal,
|
|
37
|
+
timeoutMs,
|
|
38
|
+
expired,
|
|
39
|
+
get timedOut() {
|
|
40
|
+
return timedOut;
|
|
41
|
+
},
|
|
42
|
+
clear() {
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function withCheckDeadline(promise, deadline) {
|
|
49
|
+
return deadline ? Promise.race([promise, deadline.expired]) : promise;
|
|
50
|
+
}
|
package/lib/db-push-command.mjs
CHANGED
|
@@ -56,6 +56,12 @@ import {
|
|
|
56
56
|
resolveConfirmationMode,
|
|
57
57
|
} from "./confirm-gate.mjs";
|
|
58
58
|
import { formatCommandError } from "./cli-command-runner.mjs";
|
|
59
|
+
import {
|
|
60
|
+
DEADLINE_EXCEEDED,
|
|
61
|
+
createReadOnlyCheckDeadline,
|
|
62
|
+
resolveDbCheckTimeoutMs,
|
|
63
|
+
withCheckDeadline,
|
|
64
|
+
} from "./db-check-deadline.mjs";
|
|
59
65
|
import { emitMigrationResponsibilityNotice } from "./migration-advisory.mjs";
|
|
60
66
|
import { describeProdTargetFailure } from "./cloud-targets.mjs";
|
|
61
67
|
import { cloudTargetRejectionMessage, prodRetryCommandLine } from "./deploy-app-target.mjs";
|
|
@@ -535,6 +541,7 @@ function createDbMigrationCommand(deps, command) {
|
|
|
535
541
|
return;
|
|
536
542
|
}
|
|
537
543
|
|
|
544
|
+
let checkDeadline = null;
|
|
538
545
|
try {
|
|
539
546
|
let bundleData;
|
|
540
547
|
try {
|
|
@@ -554,32 +561,48 @@ function createDbMigrationCommand(deps, command) {
|
|
|
554
561
|
});
|
|
555
562
|
let res;
|
|
556
563
|
let recoveredSuccess = null;
|
|
564
|
+
if (isCheck) {
|
|
565
|
+
checkDeadline = createReadOnlyCheckDeadline(
|
|
566
|
+
resolveDbCheckTimeoutMs(deps.processEnv.GENCOW_DB_CHECK_TIMEOUT_MS),
|
|
567
|
+
);
|
|
568
|
+
}
|
|
557
569
|
try {
|
|
558
570
|
remoteRequestStarted = true;
|
|
559
|
-
res = await
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
571
|
+
res = await withCheckDeadline(
|
|
572
|
+
deps.platformFetchImpl(
|
|
573
|
+
creds,
|
|
574
|
+
`/platform/apps/${appId}/${isInspection ? "schema-inspection" : isCheck ? "schema-check" : "schema-push"}`,
|
|
575
|
+
{
|
|
576
|
+
method: "POST",
|
|
577
|
+
headers: {
|
|
578
|
+
"Content-Type": "application/octet-stream",
|
|
579
|
+
"X-Gencow-CLI-Version": deps.cliVersion,
|
|
580
|
+
"X-Gencow-Environment": envLabel,
|
|
581
|
+
"X-Gencow-Migration-Operation-ID": receiptId,
|
|
582
|
+
"X-Gencow-Migration-Bundle-Sha256": stagedBundle.manifest.bundleSha256,
|
|
583
|
+
...(stagedBundle.manifest.artifactIdentitySha256
|
|
584
|
+
? {
|
|
585
|
+
"X-Gencow-Migration-Artifact-Identity-Sha256":
|
|
586
|
+
stagedBundle.manifest.artifactIdentitySha256,
|
|
587
|
+
}
|
|
588
|
+
: {}),
|
|
589
|
+
},
|
|
590
|
+
body: bundleData,
|
|
591
|
+
...(checkDeadline ? { signal: checkDeadline.signal } : {}),
|
|
576
592
|
},
|
|
577
|
-
|
|
578
|
-
|
|
593
|
+
),
|
|
594
|
+
checkDeadline,
|
|
579
595
|
);
|
|
596
|
+
if (res === DEADLINE_EXCEEDED) throw new Error("db:check request deadline exceeded");
|
|
580
597
|
} catch {
|
|
581
598
|
if (isCheck) {
|
|
582
|
-
emitFailure(
|
|
599
|
+
emitFailure(
|
|
600
|
+
buildMigrationCheckNoResponseDiagnostic(
|
|
601
|
+
clientCorrelationId(),
|
|
602
|
+
retryCommand,
|
|
603
|
+
checkDeadline?.timedOut ? { timeoutMs: checkDeadline.timeoutMs } : undefined,
|
|
604
|
+
),
|
|
605
|
+
);
|
|
583
606
|
return;
|
|
584
607
|
}
|
|
585
608
|
const status = await fetchMigrationOperationStatus({
|
|
@@ -613,7 +636,20 @@ function createDbMigrationCommand(deps, command) {
|
|
|
613
636
|
}
|
|
614
637
|
}
|
|
615
638
|
|
|
616
|
-
const data = recoveredSuccess
|
|
639
|
+
const data = recoveredSuccess
|
|
640
|
+
? null
|
|
641
|
+
: await withCheckDeadline(
|
|
642
|
+
res.json().catch(() => ({})),
|
|
643
|
+
checkDeadline,
|
|
644
|
+
);
|
|
645
|
+
if (data === DEADLINE_EXCEEDED) {
|
|
646
|
+
emitFailure(
|
|
647
|
+
buildMigrationCheckNoResponseDiagnostic(clientCorrelationId(), retryCommand, {
|
|
648
|
+
timeoutMs: checkDeadline.timeoutMs,
|
|
649
|
+
}),
|
|
650
|
+
);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
617
653
|
const hasJsonObjectBody = data !== null && typeof data === "object" && !Array.isArray(data);
|
|
618
654
|
if (isCheck && !recoveredSuccess && !hasJsonObjectBody) {
|
|
619
655
|
emitFailure(buildMigrationCheckInvalidResponseDiagnostic(clientCorrelationId(), retryCommand));
|
|
@@ -724,6 +760,7 @@ function createDbMigrationCommand(deps, command) {
|
|
|
724
760
|
emitJson,
|
|
725
761
|
});
|
|
726
762
|
} finally {
|
|
763
|
+
checkDeadline?.clear();
|
|
727
764
|
stagedBundle.cleanup();
|
|
728
765
|
}
|
|
729
766
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createAdmissionTransportFailure } from "./deploy-admission-transport-failure.mjs";
|
|
2
|
+
|
|
1
3
|
const DEFAULT_ADMISSION_TIMEOUT_MS = 5 * 60 * 1000;
|
|
2
4
|
|
|
3
5
|
function pendingResponse({ requestId, appName, resumeCommand = null }) {
|
|
@@ -26,10 +28,25 @@ function pendingResponse({ requestId, appName, resumeCommand = null }) {
|
|
|
26
28
|
return response;
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
// A rejected send means no HTTP response was received. It is converted to a typed
|
|
32
|
+
// transport failure here, so the CLI renders the state instead of the raw fetch message.
|
|
33
|
+
function sendAdmission(send, signal, { requestId, appName, envTarget }) {
|
|
34
|
+
const toTransportFailure = (cause) =>
|
|
35
|
+
createAdmissionTransportFailure({ cause, appName, requestId, envTarget });
|
|
36
|
+
try {
|
|
37
|
+
return Promise.resolve(send({ signal })).catch((cause) => {
|
|
38
|
+
throw toTransportFailure(cause);
|
|
39
|
+
});
|
|
40
|
+
} catch (cause) {
|
|
41
|
+
return Promise.reject(toTransportFailure(cause));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
29
45
|
export async function postDeploymentAdmissionWithTimeout({
|
|
30
46
|
send,
|
|
31
47
|
requestId = null,
|
|
32
48
|
appName,
|
|
49
|
+
envTarget = "dev",
|
|
33
50
|
resumeCommand = requestId ? `gencow deploy --resume ${requestId}` : null,
|
|
34
51
|
timeoutMs = DEFAULT_ADMISSION_TIMEOUT_MS,
|
|
35
52
|
setTimeoutImpl = setTimeout,
|
|
@@ -45,7 +62,7 @@ export async function postDeploymentAdmissionWithTimeout({
|
|
|
45
62
|
timer?.unref?.();
|
|
46
63
|
});
|
|
47
64
|
try {
|
|
48
|
-
return await Promise.race([send
|
|
65
|
+
return await Promise.race([sendAdmission(send, controller.signal, { requestId, appName, envTarget }), deadline]);
|
|
49
66
|
} finally {
|
|
50
67
|
if (timer !== undefined) clearTimeoutImpl(timer);
|
|
51
68
|
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Typed diagnosis for a deploy admission request that got no HTTP response.
|
|
2
|
+
//
|
|
3
|
+
// Two cases are told apart by a stable error code:
|
|
4
|
+
// - ERR_INVALID_URL: the request was rejected before any network I/O (for example a
|
|
5
|
+
// malformed Platform URL). Nothing was sent, so the state is known: NOT CHANGED.
|
|
6
|
+
// - Any other rejection: a network-layer failure. The request may have reached the
|
|
7
|
+
// Platform, so the state is UNKNOWN and the next step is a status check before a rerun.
|
|
8
|
+
//
|
|
9
|
+
// Printed cause text is an allowlist, never the raw message. Only the messages and codes
|
|
10
|
+
// below are printed; anything else (hosts, IPs, tokens, paths, long or multi-line text)
|
|
11
|
+
// is dropped and at most a generic "network error" line is shown.
|
|
12
|
+
|
|
13
|
+
export const ADMISSION_TRANSPORT_FAILURE_CODE = "CLI_PLATFORM_UNAVAILABLE";
|
|
14
|
+
|
|
15
|
+
// Messages the runtimes actually produce for network-layer failures seen in this CLI.
|
|
16
|
+
const KNOWN_CAUSE_MESSAGES = new Set([
|
|
17
|
+
"The socket connection was closed unexpectedly",
|
|
18
|
+
"The socket connection was closed unexpectedly.",
|
|
19
|
+
"socket closed before response",
|
|
20
|
+
"fetch failed",
|
|
21
|
+
"terminated",
|
|
22
|
+
"Unable to connect. Is the computer able to access the url?",
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
// Error codes that describe a connection-level failure.
|
|
26
|
+
const KNOWN_CAUSE_CODES = new Set([
|
|
27
|
+
"ECONNRESET",
|
|
28
|
+
"ECONNREFUSED",
|
|
29
|
+
"ECONNABORTED",
|
|
30
|
+
"ENOTFOUND",
|
|
31
|
+
"EAI_AGAIN",
|
|
32
|
+
"ETIMEDOUT",
|
|
33
|
+
"EPIPE",
|
|
34
|
+
"EHOSTUNREACH",
|
|
35
|
+
"ENETUNREACH",
|
|
36
|
+
"UND_ERR_SOCKET",
|
|
37
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
38
|
+
"ConnectionRefused",
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
const NOT_SENT_CAUSE_CODE = "ERR_INVALID_URL";
|
|
42
|
+
const SAFE_APP_ID = /^[A-Za-z0-9_-]{1,128}$/u;
|
|
43
|
+
const SAFE_REQUEST_ID = /^[A-Za-z0-9_-]{8,128}$/u;
|
|
44
|
+
|
|
45
|
+
function readCauseCode(cause) {
|
|
46
|
+
const code = cause?.code ?? cause?.cause?.code;
|
|
47
|
+
return typeof code === "string" ? code : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readAllowlistedCauseMessage(cause) {
|
|
51
|
+
const message = typeof cause?.message === "string" ? cause.message : "";
|
|
52
|
+
return KNOWN_CAUSE_MESSAGES.has(message) ? message : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function readAllowlistedCauseCode(cause) {
|
|
56
|
+
const code = readCauseCode(cause);
|
|
57
|
+
return code !== null && KNOWN_CAUSE_CODES.has(code) ? code : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The in-process message stays the original cause text, so callers that inspect the thrown
|
|
61
|
+
// error keep their existing contract. The CLI prints only the typed rendering, never this message.
|
|
62
|
+
export function createAdmissionTransportFailure({ cause, appName = null, requestId = null, envTarget = "dev" }) {
|
|
63
|
+
const originalMessage = typeof cause?.message === "string" && cause.message ? cause.message : null;
|
|
64
|
+
const error = new Error(originalMessage ?? ADMISSION_TRANSPORT_FAILURE_CODE);
|
|
65
|
+
error.code = ADMISSION_TRANSPORT_FAILURE_CODE;
|
|
66
|
+
error.deployAdmissionTransport = {
|
|
67
|
+
appName: typeof appName === "string" && SAFE_APP_ID.test(appName) ? appName : null,
|
|
68
|
+
requestId: typeof requestId === "string" && SAFE_REQUEST_ID.test(requestId) ? requestId : null,
|
|
69
|
+
envTarget: envTarget === "prod" ? "prod" : "dev",
|
|
70
|
+
requestSent: readCauseCode(cause) !== NOT_SENT_CAUSE_CODE,
|
|
71
|
+
causeMessage: readAllowlistedCauseMessage(cause),
|
|
72
|
+
causeCode: readAllowlistedCauseCode(cause),
|
|
73
|
+
attempts: null,
|
|
74
|
+
};
|
|
75
|
+
return error;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function isAdmissionTransportFailure(caught) {
|
|
79
|
+
return caught instanceof Error && caught.deployAdmissionTransport !== undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Called by the retry loop with the number of tries made for this request before it gave up.
|
|
83
|
+
export function recordAdmissionTransportAttempts(caught, attempts) {
|
|
84
|
+
if (isAdmissionTransportFailure(caught) && Number.isSafeInteger(attempts) && attempts >= 1) {
|
|
85
|
+
caught.deployAdmissionTransport.attempts = attempts;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function attemptsLine(detail) {
|
|
90
|
+
if (detail.attempts === null) return null;
|
|
91
|
+
const times = detail.attempts === 1 ? "1 time" : `${detail.attempts} times`;
|
|
92
|
+
return detail.requestId
|
|
93
|
+
? `The CLI already tried this request ${times} with the same request ID before giving up.`
|
|
94
|
+
: `The CLI already tried this request ${times} before giving up.`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function causeLine(detail) {
|
|
98
|
+
if (!detail.causeMessage && !detail.causeCode) return "Cause: network error (no safe detail)";
|
|
99
|
+
if (detail.causeMessage && detail.causeCode) return `Cause: ${detail.causeMessage} (${detail.causeCode})`;
|
|
100
|
+
return detail.causeMessage ? `Cause: ${detail.causeMessage}` : `Cause: network error (${detail.causeCode})`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function renderAdmissionTransportFailureLines(caught) {
|
|
104
|
+
const detail = caught.deployAdmissionTransport;
|
|
105
|
+
const prodFlag = detail.envTarget === "prod" ? " --prod" : "";
|
|
106
|
+
const lines = detail.requestSent
|
|
107
|
+
? [
|
|
108
|
+
`${ADMISSION_TRANSPORT_FAILURE_CODE}: The deploy request got no response from the Platform. The server may have accepted it.`,
|
|
109
|
+
]
|
|
110
|
+
: [`${ADMISSION_TRANSPORT_FAILURE_CODE}: The deploy request was not sent to the Platform.`];
|
|
111
|
+
lines.push(
|
|
112
|
+
detail.requestSent
|
|
113
|
+
? "Stage: deploy admission (bundle upload request)"
|
|
114
|
+
: "Stage: deploy admission (before the request was sent)",
|
|
115
|
+
);
|
|
116
|
+
if (detail.appName) lines.push(`App ID: ${detail.appName}`);
|
|
117
|
+
lines.push(detail.requestSent ? "Response: none received (network error)" : "Response: none (request not sent)");
|
|
118
|
+
lines.push(causeLine(detail));
|
|
119
|
+
lines.push(`Request ID: ${detail.requestId ?? "none"}`);
|
|
120
|
+
lines.push("Correlation ID: none (no response from the Platform)");
|
|
121
|
+
const attempts = attemptsLine(detail);
|
|
122
|
+
if (attempts) lines.push(attempts);
|
|
123
|
+
|
|
124
|
+
if (!detail.requestSent) {
|
|
125
|
+
lines.push("Database: NOT CHANGED (no request was sent)");
|
|
126
|
+
lines.push("Incumbent serving: PRESERVED (no request was sent)");
|
|
127
|
+
lines.push("Retryable: yes, after the Platform URL setting is fixed");
|
|
128
|
+
lines.push("Next: check the Platform URL in your CLI login/configuration, then rerun the same deploy command.");
|
|
129
|
+
return lines;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
lines.push("Database: UNKNOWN (the upload may have reached the server; nothing is confirmed)");
|
|
133
|
+
lines.push(
|
|
134
|
+
"Incumbent serving: UNKNOWN (not confirmed; a changed serving version is possible if the deploy was accepted)",
|
|
135
|
+
);
|
|
136
|
+
lines.push("Retryable: yes, but only after the status check below");
|
|
137
|
+
lines.push(
|
|
138
|
+
`Next: gencow deploy status${prodFlag} (shows the app status and last deployed time; a deployment from this attempt may or may not appear)`,
|
|
139
|
+
);
|
|
140
|
+
if (detail.requestId) {
|
|
141
|
+
lines.push(
|
|
142
|
+
`Then: if no deployment from this attempt appears, rerun with the same request ID: gencow deploy --resume ${detail.requestId}${prodFlag}`,
|
|
143
|
+
);
|
|
144
|
+
} else {
|
|
145
|
+
lines.push("Then: if no deployment from this attempt appears, rerun the same deploy command. Do not rerun first.");
|
|
146
|
+
}
|
|
147
|
+
return lines;
|
|
148
|
+
}
|